diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_http_protocol.erl | 2 | ||||
-rw-r--r-- | src/cowboy_http_req.erl | 20 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl index 71518fa..2d58315 100644 --- a/src/cowboy_http_protocol.erl +++ b/src/cowboy_http_protocol.erl @@ -402,6 +402,8 @@ ensure_response(Req=#http_req{resp_state=waiting}) -> %% Close the chunked reply. ensure_response(#http_req{method='HEAD', resp_state=chunks}) -> close; +ensure_response(#http_req{version={1, 0}, resp_state=chunks}) -> + close; ensure_response(#http_req{socket=Socket, transport=Transport, resp_state=chunks}) -> Transport:send(Socket, <<"0\r\n\r\n">>), diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl index 6b947d9..c352bbf 100644 --- a/src/cowboy_http_req.erl +++ b/src/cowboy_http_req.erl @@ -579,15 +579,21 @@ chunked_reply(Status, Req) -> -spec chunked_reply(cowboy_http:status(), cowboy_http:headers(), #http_req{}) -> {ok, #http_req{}}. chunked_reply(Status, Headers, Req=#http_req{socket=Socket, - transport=Transport, connection=Connection, pid=ReqPid, - resp_state=waiting, resp_headers=RespHeaders}) -> + transport=Transport, version=Version, connection=Connection, + pid=ReqPid, resp_state=waiting, resp_headers=RespHeaders}) -> RespConn = response_connection(Headers, Connection), - Head = response_head(Status, Headers, RespHeaders, [ - {<<"Connection">>, atom_to_connection(Connection)}, - {<<"Transfer-Encoding">>, <<"chunked">>}, + DefaultHeaders = [ {<<"Date">>, cowboy_clock:rfc1123()}, {<<"Server">>, <<"Cowboy">>} - ]), + ], + DefaultHeaders2 = case Version of + {1, 1} -> [ + {<<"Connection">>, atom_to_connection(Connection)}, + {<<"Transfer-Encoding">>, <<"chunked">>} + ] ++ DefaultHeaders; + _ -> DefaultHeaders + end, + Head = response_head(Status, Headers, RespHeaders, DefaultHeaders2), Transport:send(Socket, Head), ReqPid ! {?MODULE, resp_sent}, {ok, Req#http_req{connection=RespConn, resp_state=chunks, @@ -599,6 +605,8 @@ chunked_reply(Status, Headers, Req=#http_req{socket=Socket, -spec chunk(iodata(), #http_req{}) -> ok | {error, atom()}. chunk(_Data, #http_req{socket=_Socket, transport=_Transport, method='HEAD'}) -> ok; +chunk(Data, #http_req{socket=Socket, transport=Transport, version={1, 0}}) -> + Transport:send(Socket, Data); chunk(Data, #http_req{socket=Socket, transport=Transport, resp_state=chunks}) -> Transport:send(Socket, [integer_to_list(iolist_size(Data), 16), <<"\r\n">>, Data, <<"\r\n">>]). |