aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_protocol.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-09-10 12:25:07 +0200
committerLoïc Hoguin <[email protected]>2012-09-10 12:26:04 +0200
commit79839b7bb5ae3aef77eb7ab704efa6168927845f (patch)
tree8ddb398b58d2a2665562e65a031c2b5e7bb84ff8 /src/cowboy_protocol.erl
parent6fa734b487102ed1436fd61598d51817a46a9b75 (diff)
downloadcowboy-79839b7bb5ae3aef77eb7ab704efa6168927845f.tar.gz
cowboy-79839b7bb5ae3aef77eb7ab704efa6168927845f.tar.bz2
cowboy-79839b7bb5ae3aef77eb7ab704efa6168927845f.zip
Replace cowboy_req:path/1 with cowboy_req:raw_path/1
The latter is much more useful than the former, which ends up being removed.
Diffstat (limited to 'src/cowboy_protocol.erl')
-rw-r--r--src/cowboy_protocol.erl22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index 6bb8ff5..65012a5 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -63,6 +63,7 @@
timeout :: timeout(),
buffer = <<>> :: binary(),
host_tokens = undefined :: undefined | cowboy_dispatcher:tokens(),
+ path_tokens = undefined :: undefined | '*' | cowboy_dispatcher:tokens(),
hibernate = false :: boolean(),
loop_timeout = infinity :: timeout(),
loop_timeout_ref :: undefined | reference()
@@ -133,14 +134,15 @@ request({http_request, Method, {abs_path, AbsPath}, Version},
req_keepalive=Keepalive, max_keepalive=MaxKeepalive,
onresponse=OnResponse, urldecode={URLDecFun, URLDecArg}=URLDec}) ->
URLDecode = fun(Bin) -> URLDecFun(Bin, URLDecArg) end,
- {Path, RawPath, Qs} = cowboy_dispatcher:split_path(AbsPath, URLDecode),
+ {PathTokens, RawPath, Qs}
+ = cowboy_dispatcher:split_path(AbsPath, URLDecode),
ConnAtom = if Keepalive < MaxKeepalive -> version_to_connection(Version);
true -> close
end,
parse_header(#http_req{socket=Socket, transport=Transport,
connection=ConnAtom, pid=self(), method=Method, version=Version,
- path=Path, raw_path=RawPath, raw_qs=Qs, onresponse=OnResponse,
- urldecode=URLDec}, State);
+ path=RawPath, raw_qs=Qs, onresponse=OnResponse, urldecode=URLDec},
+ State#state{path_tokens=PathTokens});
request({http_request, Method, '*', Version},
State=#state{socket=Socket, transport=Transport,
req_keepalive=Keepalive, max_keepalive=MaxKeepalive,
@@ -150,8 +152,8 @@ request({http_request, Method, '*', Version},
end,
parse_header(#http_req{socket=Socket, transport=Transport,
connection=ConnAtom, pid=self(), method=Method, version=Version,
- path='*', raw_path= <<"*">>, raw_qs= <<>>, onresponse=OnResponse,
- urldecode=URLDec}, State);
+ path= <<"*">>, raw_qs= <<>>, onresponse=OnResponse,
+ urldecode=URLDec}, State#state{path_tokens='*'});
request({http_request, _Method, _URI, _Version}, State) ->
error_terminate(501, State);
request({http_error, <<"\r\n">>},
@@ -248,13 +250,13 @@ onrequest(Req, State=#state{onrequest=OnRequest}) ->
end.
-spec dispatch(#http_req{}, #state{}) -> ok.
-dispatch(Req=#http_req{path=Path},
- State=#state{dispatch=Dispatch, host_tokens=HostTokens}) ->
- case cowboy_dispatcher:match(HostTokens, Path, Dispatch) of
+dispatch(Req, State=#state{dispatch=Dispatch,
+ host_tokens=HostTokens, path_tokens=PathTokens}) ->
+ case cowboy_dispatcher:match(HostTokens, PathTokens, Dispatch) of
{ok, Handler, Opts, Binds, HostInfo, PathInfo} ->
handler_init(Req#http_req{host_info=HostInfo, path_info=PathInfo,
bindings=Binds}, State#state{handler={Handler, Opts},
- host_tokens=undefined});
+ host_tokens=undefined, path_tokens=undefined});
{error, notfound, host} ->
error_terminate(400, State);
{error, notfound, path} ->
@@ -408,7 +410,7 @@ next_request(Req=#http_req{connection=Conn}, State=#state{
case {HandlerRes, BodyRes, RespRes, Conn} of
{ok, ok, ok, keepalive} ->
?MODULE:parse_request(State#state{
- buffer=Buffer, host_tokens=undefined,
+ buffer=Buffer, host_tokens=undefined, path_tokens=undefined,
req_empty_lines=0, req_keepalive=Keepalive + 1});
_Closed ->
terminate(State)