mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-16 05:00:24 +00:00
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.
This commit is contained in:
parent
4048499af2
commit
c32db277c8
3 changed files with 34 additions and 12 deletions
|
@ -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) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue