mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 20:50:24 +00:00
Fix an issue for replies in onresponse mishandling headers
Reported and fixed over email by Adrian Roe.
This commit is contained in:
parent
4b15d8f6e3
commit
823a82b8f2
2 changed files with 41 additions and 4 deletions
|
@ -163,7 +163,8 @@
|
|||
| {non_neg_integer(), resp_body_fun()},
|
||||
|
||||
%% Functions.
|
||||
onresponse = undefined :: undefined | cowboy_protocol:onresponse_fun()
|
||||
onresponse = undefined :: undefined | already_called
|
||||
| cowboy_protocol:onresponse_fun()
|
||||
}).
|
||||
|
||||
-opaque req() :: #http_req{}.
|
||||
|
@ -1162,13 +1163,17 @@ to_list(Req) ->
|
|||
response(Status, Headers, RespHeaders, DefaultHeaders, Body, Req=#http_req{
|
||||
socket=Socket, transport=Transport, version=Version,
|
||||
pid=ReqPid, onresponse=OnResponse}) ->
|
||||
FullHeaders = response_merge_headers(Headers, RespHeaders, DefaultHeaders),
|
||||
FullHeaders = case OnResponse of
|
||||
already_called -> Headers;
|
||||
_ -> response_merge_headers(Headers, RespHeaders, DefaultHeaders)
|
||||
end,
|
||||
Req2 = case OnResponse of
|
||||
already_called -> Req;
|
||||
undefined -> Req;
|
||||
OnResponse -> OnResponse(Status, FullHeaders, Body,
|
||||
%% Don't call 'onresponse' from the hook itself.
|
||||
Req#http_req{resp_headers=[], resp_body= <<>>,
|
||||
onresponse=undefined})
|
||||
onresponse=already_called})
|
||||
end,
|
||||
ReplyType = case Req2#http_req.resp_state of
|
||||
waiting ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue