mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Add streaming without chunking for HTTP/1.1
If content-length is set in the response headers we can skip chunked transfer-encoding.
This commit is contained in:
parent
69451dd98d
commit
f08f4610a0
4 changed files with 140 additions and 38 deletions
|
@ -220,6 +220,32 @@ do(<<"stream_body">>, Req0, Opts) ->
|
|||
cowboy_req:stream_body(<<0:800000>>, fin, Req0),
|
||||
{ok, Req0, Opts}
|
||||
end;
|
||||
do(<<"stream_body_content_length">>, Req0, Opts) ->
|
||||
case cowboy_req:binding(arg, Req0) of
|
||||
<<"fin0">> ->
|
||||
Req1 = cowboy_req:set_resp_header(<<"content-length">>, <<"12">>, Req0),
|
||||
Req = cowboy_req:stream_reply(200, Req1),
|
||||
cowboy_req:stream_body(<<"Hello world!">>, nofin, Req),
|
||||
cowboy_req:stream_body(<<>>, fin, Req),
|
||||
{ok, Req, Opts};
|
||||
<<"multiple">> ->
|
||||
Req1 = cowboy_req:set_resp_header(<<"content-length">>, <<"12">>, Req0),
|
||||
Req = cowboy_req:stream_reply(200, Req1),
|
||||
cowboy_req:stream_body(<<"Hello ">>, nofin, Req),
|
||||
cowboy_req:stream_body(<<"world">>, nofin, Req),
|
||||
cowboy_req:stream_body(<<"!">>, fin, Req),
|
||||
{ok, Req, Opts};
|
||||
<<"nofin">> ->
|
||||
Req1 = cowboy_req:set_resp_header(<<"content-length">>, <<"12">>, Req0),
|
||||
Req = cowboy_req:stream_reply(200, Req1),
|
||||
cowboy_req:stream_body(<<"Hello world!">>, nofin, Req),
|
||||
{ok, Req, Opts};
|
||||
<<"nofin-error">> ->
|
||||
Req1 = cowboy_req:set_resp_header(<<"content-length">>, <<"12">>, Req0),
|
||||
Req = cowboy_req:stream_reply(200, Req1),
|
||||
cowboy_req:stream_body(<<"Hello">>, nofin, Req),
|
||||
{ok, Req, Opts}
|
||||
end;
|
||||
do(<<"stream_trailers">>, Req0, Opts) ->
|
||||
case cowboy_req:binding(arg, Req0) of
|
||||
<<"large">> ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue