aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-04-14 01:26:02 +0200
committerLoïc Hoguin <[email protected]>2011-04-14 01:32:02 +0200
commitc32db277c82054597ac4200424fa4cbe55448ea8 (patch)
treebf0921a6fe8d0de3fa9729195dfea45b8d1c1305 /test/http_SUITE.erl
parent4048499af2a19ac876da30236bbf06fe3f7ffdb3 (diff)
downloadcowboy-c32db277c82054597ac4200424fa4cbe55448ea8.tar.gz
cowboy-c32db277c82054597ac4200424fa4cbe55448ea8.tar.bz2
cowboy-c32db277c82054597ac4200424fa4cbe55448ea8.zip
Fix a bug where dupe headers were sent in cowboy_http_req:reply/4.
Now the server defines default headers that can be overwritten by the handler simply by passing them to the reply/4 function. Default headers include, for now, Connection and Content-Length headers. Note that it isn't enough to change the Connection header to close a keep-alive connection server-side.
Diffstat (limited to 'test/http_SUITE.erl')
-rw-r--r--test/http_SUITE.erl21
1 files changed, 18 insertions, 3 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index 663878b..30ec709 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -18,7 +18,7 @@
-export([all/0, groups/0, init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2]). %% ct.
--export([pipeline/1, raw/1]). %% http.
+-export([headers_dupe/1, pipeline/1, raw/1]). %% http.
-export([http_200/1, http_404/1]). %% http and https.
%% ct.
@@ -28,7 +28,7 @@ all() ->
groups() ->
BaseTests = [http_200, http_404],
- [{http, [], [pipeline, raw] ++ BaseTests},
+ [{http, [], [headers_dupe, pipeline, raw] ++ BaseTests},
{https, [], BaseTests}].
init_per_suite(Config) ->
@@ -76,7 +76,11 @@ end_per_group(https, _Config) ->
init_http_dispatch() ->
[
- {["localhost"], [{[], http_handler, []}]}
+ {["localhost"], [
+ {["headers", "dupe"], http_handler,
+ [{headers, [{"Connection", "close"}]}]},
+ {[], http_handler, []}
+ ]}
].
init_https_dispatch() ->
@@ -84,6 +88,17 @@ init_https_dispatch() ->
%% http.
+headers_dupe(Config) ->
+ {port, Port} = lists:keyfind(port, 1, Config),
+ {ok, Socket} = gen_tcp:connect("localhost", Port,
+ [binary, {active, false}, {packet, raw}]),
+ ok = gen_tcp:send(Socket,
+ "GET /headers/dupe HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"),
+ {ok, Data} = gen_tcp:recv(Socket, 0, 6000),
+ {_Start, _Length} = binary:match(Data, <<"Connection: close">>),
+ nomatch = binary:match(Data, <<"Connection: keep-alive">>),
+ ok = gen_tcp:close(Socket).
+
pipeline(Config) ->
{port, Port} = lists:keyfind(port, 1, Config),
{ok, Socket} = gen_tcp:connect("localhost", Port,