0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Add the chunked option for HTTP/1.1

It allows disabling the chunked transfer-encoding. It
can also be disabled on a per-request basis, although
it will be ignored for responses that are not streamed.
This commit is contained in:
Loïc Hoguin 2018-11-18 13:21:36 +01:00
parent 417032a445
commit 8d6d78575f
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 129 additions and 14 deletions

View file

@ -8,6 +8,19 @@
init(Req, State) ->
set_options(cowboy_req:binding(key, Req), Req, State).
set_options(<<"chunked_false">>, Req0, State) ->
%% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast.
#{pid := Pid, streamid := StreamID} = Req0,
Pid ! {{Pid, StreamID}, {set_options, #{chunked => false}}},
Req = cowboy_req:stream_reply(200, Req0),
cowboy_req:stream_body(<<0:8000000>>, fin, Req),
{ok, Req, State};
set_options(<<"chunked_false_ignored">>, Req0, State) ->
%% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast.
#{pid := Pid, streamid := StreamID} = Req0,
Pid ! {{Pid, StreamID}, {set_options, #{chunked => false}}},
Req = cowboy_req:reply(200, #{}, <<"Hello world!">>, Req0),
{ok, Req, State};
set_options(<<"idle_timeout_short">>, Req0, State) ->
%% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast.
#{pid := Pid, streamid := StreamID} = Req0,