Commits

Anonymous committed 765b3ff

added peer to wrq interface

Comments (0)

Files changed (3)

include/wm_reqdata.hrl

--record(wm_reqdata, {method, version,
+-record(wm_reqdata, {method, version, peer,
                      disp_path, path, raw_path, path_info, path_tokens,
                      app_root,response_code,
                      req_cookie, req_qs, req_headers, req_body,

src/webmachine_request_srv.erl

     %%process_flag(trap_exit, true),
     %% Calling get_peer() here is a little bit of an ugly way to populate the
     %% client IP address but it will do for now.
-    {_, State} = get_peer(#state{socket=Socket,
+    {Peer, State} = get_peer(#state{socket=Socket,
          reqdata=wrq:create(Method,Version,RawPath,Headers)}),
-    BodyState = do_recv_body(State),
+    BodyState = do_recv_body(State#state{
+                               reqdata=wrq:set_peer(Peer,State#state.reqdata)}),
     LogData = #wm_log_data{start_time=now(),
 			   method=Method,
 			   headers=Headers,
 -author('Justin Sheehy <justin@basho.com>').
 
 -export([create/4,load_dispatch_data/5]).
--export([method/1,version/1,disp_path/1,path/1,raw_path/1,path_info/1,
+-export([method/1,version/1,peer/1,disp_path/1,path/1,raw_path/1,path_info/1,
          response_code/1,req_cookie/1,req_qs/1,req_headers/1,req_body/1,
          resp_redirect/1,resp_headers/1,resp_body/1,
         app_root/1,path_tokens/1]).
          get_resp_header/2,set_resp_header/3,set_resp_headers/2,
          set_disp_path/2,set_req_body/2,set_resp_body/2,set_response_code/2,
          merge_resp_headers/2,remove_resp_header/2,append_to_response_body/2,
-         get_cookie_value/2,get_qs_value/2,get_qs_value/3]).
+         get_cookie_value/2,get_qs_value/2,get_qs_value/3,set_peer/2]).
 
 -include_lib("include/wm_reqdata.hrl").
 
       path=defined_in_create,
       req_cookie=defined_in_create,
       req_qs=defined_in_create,
+      peer=defined_in_wm_req_srv_init,
       req_body=defined_in_wm_req_srv_init,
       app_root=defined_in_load_dispatch_data,
       path_info=defined_in_load_dispatch_data,
   when is_tuple(Version), size(Version) == 2,
      is_integer(element(1,Version)), is_integer(element(2,Version)) -> Version.
 
+peer(_RD = #wm_reqdata{peer=Peer}) when is_list(Peer) -> Peer.
+
 app_root(_RD = #wm_reqdata{app_root=AR}) when is_list(AR) -> AR.
 
 % all three paths below are strings
 do_redirect(true, RD) ->  RD#wm_reqdata{resp_redirect=true};
 do_redirect(false, RD) -> RD#wm_reqdata{resp_redirect=false}.
 
+set_peer(P, RD) when is_list(P) -> RD#wm_reqdata{peer=P}. % string
+
 set_disp_path(P, RD) when is_list(P) -> RD#wm_reqdata{disp_path=P}. % string
 
 set_req_body(Body, RD) -> RD#wm_reqdata{req_body=Body}.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.