@@ -84,6 +84,7 @@ defmodule HttpRouter do
8484 @ http_methods [ :get , :post , :put , :patch , :delete , :any ]
8585
8686 @ default_options [
87+ add_match_details_to_private: true ,
8788 allow_copy_req_content_type: true ,
8889 allow_head: true ,
8990 allow_method_override: true ,
@@ -176,7 +177,7 @@ defmodule HttpRouter do
176177 # its face when accessing an undefined route.
177178 def do_match ( _ , _ ) do
178179 fn conn ->
179- conn |> send_resp ( 404 , "" )
180+ conn |> Plug.Conn . send_resp ( 404 , "" )
180181 end
181182 end
182183
@@ -300,6 +301,7 @@ defmodule HttpRouter do
300301
301302 ## Private API
302303
304+ defp ignore_args ( nil ) , do: ""
303305 defp ignore_args ( str ) do
304306 str
305307 |> String . to_char_list
@@ -353,9 +355,9 @@ defmodule HttpRouter do
353355 do_build_match :options , route , body , caller
354356 end
355357 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
359361
360362 [ #do_build_match(method, route <> ".json", body_json, caller),
361363 #do_build_match(method, route <> ".xml", body_xml, caller),
@@ -375,8 +377,8 @@ defmodule HttpRouter do
375377 end
376378 end
377379
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
380382 header = case add_header do
381383 :json -> [ { "accept" , "application/json" } ]
382384 :xml -> [ { "accept" , "application/xml" } ]
@@ -385,8 +387,14 @@ defmodule HttpRouter do
385387
386388 quote do
387389 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 ) )
390398 end
391399 end
392400
0 commit comments