aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/http.hrl3
-rw-r--r--src/cowboy_protocol.erl22
-rw-r--r--src/cowboy_req.erl20
-rw-r--r--src/cowboy_rest.erl2
-rw-r--r--src/cowboy_websocket.erl2
-rw-r--r--test/rest_forbidden_resource.erl2
6 files changed, 22 insertions, 29 deletions
diff --git a/include/http.hrl b/include/http.hrl
index 06c21f0..5440d8f 100644
--- a/include/http.hrl
+++ b/include/http.hrl
@@ -28,9 +28,8 @@
host = undefined :: undefined | binary(),
host_info = undefined :: undefined | cowboy_dispatcher:tokens(),
port = undefined :: undefined | inet:port_number(),
- path = undefined :: undefined | '*' | cowboy_dispatcher:tokens(),
+ path = undefined :: undefined | binary(),
path_info = undefined :: undefined | cowboy_dispatcher:tokens(),
- raw_path = undefined :: undefined | binary(),
qs_vals = undefined :: undefined | list({binary(), binary() | true}),
raw_qs = undefined :: undefined | binary(),
bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
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)
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 54693f7..fd1399d 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -31,7 +31,6 @@
-export([port/1]).
-export([path/1]).
-export([path_info/1]).
--export([raw_path/1]).
-export([qs_val/2]).
-export([qs_val/3]).
-export([qs_vals/1]).
@@ -147,12 +146,8 @@ host_info(Req) ->
port(Req) ->
{Req#http_req.port, Req}.
-%% @doc Return the path segments for the path requested.
-%%
-%% Following RFC2396, this function may return path segments containing any
-%% character, including <em>/</em> if, and only if, a <em>/</em> was escaped
-%% and part of a path segment in the path requested.
--spec path(Req) -> {cowboy_dispatcher:tokens(), Req} when Req::req().
+%% @doc Return the path binary string.
+-spec path(Req) -> {binary(), Req} when Req::req().
path(Req) ->
{Req#http_req.path, Req}.
@@ -163,11 +158,6 @@ path(Req) ->
path_info(Req) ->
{Req#http_req.path_info, Req}.
-%% @doc Return the raw path directly taken from the request.
--spec raw_path(Req) -> {binary(), Req} when Req::req().
-raw_path(Req) ->
- {Req#http_req.raw_path, Req}.
-
%% @equiv qs_val(Name, Req, undefined)
-spec qs_val(binary(), Req)
-> {binary() | true | undefined, Req} when Req::req().
@@ -820,12 +810,14 @@ upgrade_reply(Status, Headers, Req=#http_req{
%% @doc Compact the request data by removing all non-system information.
%%
-%% This essentially removes the path, query string, bindings and headers.
+%% This essentially removes the host and path info, query string, bindings,
+%% headers and cookies.
+%%
%% Use it when you really need to save up memory, for example when having
%% many concurrent long-running connections.
-spec compact(Req) -> Req when Req::req().
compact(Req) ->
- Req#http_req{host_info=undefined, path=undefined,
+ Req#http_req{host_info=undefined,
path_info=undefined, qs_vals=undefined,
bindings=undefined, headers=[],
p_headers=[], cookies=[]}.
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index be2baaf..2f3a2e4 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -706,7 +706,7 @@ process_post(Req, State) ->
is_conflict(Req, State) ->
expect(Req, State, is_conflict, false, fun put_resource/2, 409).
-put_resource(Req=#http_req{raw_path=RawPath, meta=Meta}, State) ->
+put_resource(Req=#http_req{path=RawPath, meta=Meta}, State) ->
Req2 = Req#http_req{meta=[{put_path, RawPath}|Meta]},
put_resource(Req2, State, fun is_new_resource/2).
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index 4604e39..b669ef7 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -156,7 +156,7 @@ upgrade_denied(#http_req{socket=Socket, transport=Transport,
websocket_handshake(State=#state{version=0, origin=Origin,
challenge={Key1, Key2}}, Req=#http_req{socket=Socket,
transport=Transport, host=Host, port=Port,
- raw_path=Path, raw_qs=QS}, HandlerState) ->
+ path=Path, raw_qs=QS}, HandlerState) ->
Location = hixie76_location(Transport:name(), Host, Port, Path, QS),
{ok, Req2} = cowboy_req:upgrade_reply(
<<"101 WebSocket Protocol Handshake">>,
diff --git a/test/rest_forbidden_resource.erl b/test/rest_forbidden_resource.erl
index 9d3cd95..d34e7b2 100644
--- a/test/rest_forbidden_resource.erl
+++ b/test/rest_forbidden_resource.erl
@@ -27,7 +27,7 @@ post_is_create(Req, State) ->
{true, Req, State}.
create_path(Req, State) ->
- {Path, Req2} = cowboy_req:raw_path(Req),
+ {Path, Req2} = cowboy_req:path(Req),
{Path, Req2, State}.
to_text(Req, State) ->