Browse Source

Save the raw path string in the request.

Loïc Hoguin 14 years ago
parent
commit
b874b28561
3 changed files with 9 additions and 8 deletions
  1. 3 3
      include/http.hrl
  2. 2 2
      src/cowboy_dispatcher.erl
  3. 4 3
      src/cowboy_http_protocol.erl

+ 3 - 3
include/http.hrl

@@ -21,9 +21,9 @@
 	peer       = undefined :: undefined | {Address::ip_address(), Port::port_number()},
 	host       = undefined :: undefined | path_tokens(),
 	raw_host   = undefined :: undefined | string(),
-	path       = undefined :: undefined | path_tokens(), %% todo
-	raw_path   = undefined :: undefined | string(), %% todo
-	qs_vals    = undefined :: undefined | bindings(), %% todo
+	path       = undefined :: undefined | path_tokens(),
+	raw_path   = undefined :: undefined | string(),
+	qs_vals    = undefined :: undefined | bindings(),
 	raw_qs     = undefined :: undefined | string(),
 	bindings   = undefined :: undefined | bindings(),
 	headers    = []        :: http_headers()

+ 2 - 2
src/cowboy_dispatcher.erl

@@ -30,10 +30,10 @@ split_path('*') ->
 split_path(Path) ->
 	case string:chr(Path, $?) of
 		0 ->
-			{string:tokens(Path, "/"), []};
+			{string:tokens(Path, "/"), Path, []};
 		N ->
 			{Path2, [$?|Qs]} = lists:split(N - 1, Path),
-			{string:tokens(Path2, "/"), Qs}
+			{string:tokens(Path2, "/"), Path2, Qs}
 	end.
 
 -spec match(Host::path_tokens(), Path::path_tokens(), Dispatch::dispatch())

+ 4 - 3
src/cowboy_http_protocol.erl

@@ -64,15 +64,16 @@ request({http_request, _Method, _URI, Version}, State)
 %% @todo We need to cleanup the URI properly.
 request({http_request, Method, {abs_path, AbsPath}, Version},
 		State=#state{socket=Socket, transport=Transport}) ->
-	{Path, Qs} = cowboy_dispatcher:split_path(AbsPath),
+	{Path, RawPath, Qs} = cowboy_dispatcher:split_path(AbsPath),
 	{ok, Peer} = Transport:peername(Socket),
 	wait_header(#http_req{socket=Socket, transport=Transport, method=Method,
-		version=Version, peer=Peer, path=Path, raw_qs=Qs}, State);
+		version=Version, peer=Peer, path=Path, raw_path=RawPath, raw_qs=Qs},
+		State);
 request({http_request, Method, '*', Version},
 		State=#state{socket=Socket, transport=Transport}) ->
 	{ok, Peer} = Transport:peername(Socket),
 	wait_header(#http_req{socket=Socket, transport=Transport, method=Method,
-		version=Version, peer=Peer, path='*', raw_qs=[]}, State);
+		version=Version, peer=Peer, path='*', raw_path="*", raw_qs=[]}, State);
 request({http_request, _Method, _URI, _Version}, State) ->
 	error_terminate(501, State);
 request({http_error, "\r\n"}, State) ->