aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-09-16 23:54:29 +0200
committerLoïc Hoguin <[email protected]>2012-09-17 13:57:28 +0200
commit905083a7fddcc7680405c504a646da9a70e3059e (patch)
tree22a3ae785903e5a2f5bb0caf0f51b669e21896c1
parent350d4ae3f2e9973b3638b06c7092370afa08e634 (diff)
downloadcowboy-905083a7fddcc7680405c504a646da9a70e3059e.tar.gz
cowboy-905083a7fddcc7680405c504a646da9a70e3059e.tar.bz2
cowboy-905083a7fddcc7680405c504a646da9a70e3059e.zip
Add the private set_connection/2 function used by cowboy_protocol
-rw-r--r--src/cowboy_protocol.erl11
-rw-r--r--src/cowboy_req.erl9
2 files changed, 12 insertions, 8 deletions
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index 8323b80..8ddd40d 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -199,15 +199,10 @@ header({http_header, _I, 'Host', _R, RawHost}, Req,
%% Ignore Host headers if we already have it.
header({http_header, _I, 'Host', _R, _V}, Req, State) ->
parse_header(Req, State);
-header({http_header, _I, 'Connection', _R, Connection},
- Req=#http_req{headers=Headers}, State=#state{
- req_keepalive=Keepalive, max_keepalive=MaxKeepalive})
+header({http_header, _I, 'Connection', _R, Connection}, Req,
+ State=#state{req_keepalive=Keepalive, max_keepalive=MaxKeepalive})
when Keepalive < MaxKeepalive ->
- Req2 = Req#http_req{headers=[{'Connection', Connection}|Headers]},
- {ok, ConnTokens, Req3}
- = cowboy_req:parse_header('Connection', Req2),
- ConnAtom = cowboy_http:connection_to_atom(ConnTokens),
- parse_header(Req3#http_req{connection=ConnAtom}, State);
+ parse_header(cowboy_req:set_connection(Connection, Req), State);
header({http_header, _I, Field, _R, Value}, Req, State) ->
Field2 = format_header(Field),
parse_header(Req#http_req{headers=[{Field2, Value}|Req#http_req.headers]},
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 08e4155..8653efe 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -104,6 +104,7 @@
%% Private setter/getter API.
-export([set_host/4]).
+-export([set_connection/2]).
%% Misc API.
-export([compact/1]).
@@ -919,6 +920,14 @@ ensure_response(#http_req{socket=Socket, transport=Transport,
set_host(Host, Port, RawHost, Req=#http_req{headers=Headers}) ->
Req#http_req{host=Host, port=Port, headers=[{'Host', RawHost}|Headers]}.
+%% @private
+-spec set_connection(binary(), Req) -> Req when Req::req().
+set_connection(RawConnection, Req=#http_req{headers=Headers}) ->
+ Req2 = Req#http_req{headers=[{'Connection', RawConnection}|Headers]},
+ {ok, ConnTokens, Req3} = parse_header('Connection', Req2),
+ ConnAtom = cowboy_http:connection_to_atom(ConnTokens),
+ Req3#http_req{connection=ConnAtom}.
+
%% Misc API.
%% @doc Compact the request data by removing all non-system information.