@@ -84,6 +84,16 @@ defmodule HttpRouter do
84
84
@ typep ast :: tuple
85
85
@ http_methods [ :get , :post , :put , :patch , :delete , :any ]
86
86
87
+ @ app A . get_env ( :http_router , :otp_app , :http_router )
88
+ @ options [
89
+ allow_copy_req_content_type: A . get_env ( @ app , :allow_copy_req_content_type , true ) ,
90
+ allow_head: A . get_env ( @ app , :allow_head , true ) ,
91
+ allow_method_override: A . get_env ( @ app , :allow_method_override , true ) ,
92
+ default_content_type: A . get_env ( @ app , :default_content_type , "text/html; charset=utf-8" ) ,
93
+ json_decoder: A . get_env ( @ app , :json_decoder , Poison ) ,
94
+ parsers: A . get_env ( @ app , :parsers , [ :json , :urlencoded , :multipart ] )
95
+ ]
96
+
87
97
## Macros
88
98
89
99
@ doc false
@@ -97,10 +107,10 @@ defmodule HttpRouter do
97
107
Module . register_attribute ( __MODULE__ , :version , accumulate: false )
98
108
99
109
# Plugs we want early in the stack
100
- parsers_opts = [ parsers: options [ :parsers ] ]
110
+ parsers_opts = [ parsers: unquote ( @ options [ :parsers ] ) ]
101
111
if :json in parsers_opts [ :parsers ] do
102
112
parsers_opts = parsers_opts
103
- |> Keyword . put ( :json_decoder , options [ :json_decoder ] )
113
+ |> Keyword . put ( :json_decoder , unquote ( @ options [ :json_decoder ] ) )
104
114
end
105
115
106
116
plug Plug.Parsers , parsers_opts
@@ -114,15 +124,15 @@ defmodule HttpRouter do
114
124
defaults = [ { :match , [ ] , true } ,
115
125
{ :dispatch , [ ] , true } ]
116
126
117
- if options [ :allow_copy_req_content_type ] == true do
127
+ if @ options [ :allow_copy_req_content_type ] == true do
118
128
defaults = [ { :copy_req_content_type , [ ] , true } | defaults ]
119
129
end
120
130
121
- if options [ :allow_method_override ] == true do
131
+ if @ options [ :allow_method_override ] == true do
122
132
defaults = [ { Plug.MethodOverride , [ ] , true } | defaults ]
123
133
end
124
134
125
- if options [ :allow_head ] == true do
135
+ if @ options [ :allow_head ] == true do
126
136
defaults = [ { Plug.Head , [ ] , true } | defaults ]
127
137
end
128
138
@@ -141,9 +151,9 @@ defmodule HttpRouter do
141
151
142
152
defoverridable [ init: 1 , call: 2 ]
143
153
144
- if options [ :allow_copy_req_content_type ] == true do
154
+ if unquote ( @ options [ :allow_copy_req_content_type ] ) == true do
145
155
def copy_req_content_type ( conn , _opts ) do
146
- default = options [ :default_content_type ]
156
+ default = unquote ( @ options [ :default_content_type ] )
147
157
content_type = case Plug.Conn . get_req_header conn , "content-type" do
148
158
[ content_type ] -> content_type
149
159
_ -> default
@@ -289,17 +299,6 @@ defmodule HttpRouter do
289
299
290
300
## Private API
291
301
292
- @ app A . get_env ( :http_router , :otp_app , :http_router )
293
- @ doc false
294
- def options , do: [
295
- allow_copy_req_content_type: A . get_env ( @ app , :allow_copy_req_content_type , true ) ,
296
- allow_head: A . get_env ( @ app , :allow_head , true ) ,
297
- allow_method_override: A . get_env ( @ app , :allow_method_override , true ) ,
298
- default_content_type: A . get_env ( @ app , :default_content_type , "text/html; charset=utf-8" ) ,
299
- json_decoder: A . get_env ( @ app , :json_decoder , Poison ) ,
300
- parsers: A . get_env ( @ app , :parsers , [ :json , :urlencoded , :multipart ] )
301
- ]
302
-
303
302
defp ignore_args ( str ) do
304
303
str
305
304
|> String . to_char_list
0 commit comments