@@ -84,6 +84,7 @@ defmodule HttpRouter do
84
84
@ http_methods [ :get , :post , :put , :patch , :delete , :any ]
85
85
86
86
@ default_options [
87
+ add_match_details_to_private: true ,
87
88
allow_copy_req_content_type: true ,
88
89
allow_head: true ,
89
90
allow_method_override: true ,
@@ -176,7 +177,7 @@ defmodule HttpRouter do
176
177
# its face when accessing an undefined route.
177
178
def do_match ( _ , _ ) do
178
179
fn conn ->
179
- conn |> send_resp ( 404 , "" )
180
+ conn |> Plug.Conn . send_resp ( 404 , "" )
180
181
end
181
182
end
182
183
@@ -300,6 +301,7 @@ defmodule HttpRouter do
300
301
301
302
## Private API
302
303
304
+ defp ignore_args ( nil ) , do: ""
303
305
defp ignore_args ( str ) do
304
306
str
305
307
|> String . to_char_list
@@ -353,9 +355,9 @@ defmodule HttpRouter do
353
355
do_build_match :options , route , body , caller
354
356
end
355
357
defp build_match ( method , route , handler , action , caller ) do
356
- body = build_body handler , action
357
- # body_json = build_body handler, action, :json
358
- # body_xml = build_body handler, action, :xml
358
+ body = build_body handler , action , caller
359
+ # body_json = build_body handler, action, caller, :json
360
+ # body_xml = build_body handler, action, caller, :xml
359
361
360
362
[ #do_build_match(method, route <> ".json", body_json, caller),
361
363
#do_build_match(method, route <> ".xml", body_xml, caller),
@@ -375,8 +377,8 @@ defmodule HttpRouter do
375
377
end
376
378
end
377
379
378
- defp build_body ( handler , action ) , do: build_body ( handler , action , :skip )
379
- defp build_body ( handler , action , add_header ) do
380
+ defp build_body ( handler , action , caller ) , do: build_body ( handler , action , caller , :skip )
381
+ defp build_body ( handler , action , _caller , add_header ) do
380
382
header = case add_header do
381
383
:json -> [ { "accept" , "application/json" } ]
382
384
:xml -> [ { "accept" , "application/xml" } ]
@@ -385,8 +387,14 @@ defmodule HttpRouter do
385
387
386
388
quote do
387
389
opts = [ action: unquote ( action ) , args: binding ( ) ]
388
- unquote ( handler ) . call % { conn | req_headers: unquote ( header ) ++
389
- conn . req_headers } , unquote ( handler ) . init ( opts )
390
+ private = conn . private
391
+ |> Map . put ( :controller , unquote ( handler ) )
392
+ |> Map . put ( :handler , unquote ( handler ) )
393
+ |> Map . put ( :action , unquote ( action ) )
394
+
395
+ % { conn | req_headers: unquote ( header ) ++ conn . req_headers ,
396
+ private: private }
397
+ |> unquote ( handler ) . call ( unquote ( handler ) . init ( opts ) )
390
398
end
391
399
end
392
400
0 commit comments