aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_handler.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_handler.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_handler.erl')
-rw-r--r--test/http_handler.erl12
1 files changed, 8 insertions, 4 deletions
diff --git a/test/http_handler.erl b/test/http_handler.erl
index 3882e17..76a85d4 100644
--- a/test/http_handler.erl
+++ b/test/http_handler.erl
@@ -4,11 +4,15 @@
-behaviour(cowboy_http_handler).
-export([init/3, handle/2, terminate/2]).
-init({_Transport, http}, Req, _Opts) ->
- {ok, Req, undefined}.
+-record(state, {headers, body}).
-handle(Req, State) ->
- {ok, Req2} = cowboy_http_req:reply(200, [], "http_handler", Req),
+init({_Transport, http}, Req, Opts) ->
+ Headers = proplists:get_value(headers, Opts, []),
+ Body = proplists:get_value(body, Opts, "http_handler"),
+ {ok, Req, #state{headers=Headers, body=Body}}.
+
+handle(Req, State=#state{headers=Headers, body=Body}) ->
+ {ok, Req2} = cowboy_http_req:reply(200, Headers, Body, Req),
{ok, Req2, State}.
terminate(_Req, _State) ->