aboutsummaryrefslogtreecommitdiffstats
path: root/test/compress_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-09 17:42:37 +0100
committerLoïc Hoguin <[email protected]>2018-11-09 17:42:37 +0100
commitd7b7580b3913c17b404319cc4c153748d5e59194 (patch)
tree3026f38e4bcfdcb26d067a4e5aec6d401700c3cc /test/compress_SUITE.erl
parent29043aa7b4d11e377bc76d453f592ea5a6df1f43 (diff)
downloadcowboy-d7b7580b3913c17b404319cc4c153748d5e59194.tar.gz
cowboy-d7b7580b3913c17b404319cc4c153748d5e59194.tar.bz2
cowboy-d7b7580b3913c17b404319cc4c153748d5e59194.zip
Add sendfile support to cowboy_req:stream_body
It is now possible to stream one or more sendfile tuples. A simple example of what can now be done would be for example to build a tar file on the fly using the sendfile syscall for sending the files, or to support Range requests with more than one range with the sendfile syscall. When using cowboy_compress_h unfortunately we have to read the file in order to send it. More options will be added at a later time to make sure users don't read too much into memory. This is a new feature however so existing code is not affected. Also rework cowboy_http's data sending to be flatter.
Diffstat (limited to 'test/compress_SUITE.erl')
-rw-r--r--test/compress_SUITE.erl18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/compress_SUITE.erl b/test/compress_SUITE.erl
index 36f8865..06b3950 100644
--- a/test/compress_SUITE.erl
+++ b/test/compress_SUITE.erl
@@ -121,6 +121,24 @@ gzip_stream_reply(Config) ->
_ = zlib:gunzip(GzBody),
ok.
+gzip_stream_reply_sendfile(Config) ->
+ doc("Stream reply using sendfile for some chunks; get a gzipped response."),
+ {200, Headers, GzBody} = do_get("/stream_reply/sendfile",
+ [{<<"accept-encoding">>, <<"gzip">>}], Config),
+ {_, <<"gzip">>} = lists:keyfind(<<"content-encoding">>, 1, Headers),
+ file:write_file("/tmp/test.gz", GzBody),
+ _ = zlib:gunzip(GzBody),
+ ok.
+
+gzip_stream_reply_sendfile_fin(Config) ->
+ doc("Stream reply using sendfile for some chunks; get a gzipped response."),
+ {200, Headers, GzBody} = do_get("/stream_reply/sendfile_fin",
+ [{<<"accept-encoding">>, <<"gzip">>}], Config),
+ {_, <<"gzip">>} = lists:keyfind(<<"content-encoding">>, 1, Headers),
+ file:write_file("/tmp/test.gz", GzBody),
+ _ = zlib:gunzip(GzBody),
+ ok.
+
gzip_stream_reply_content_encoding(Config) ->
doc("Stream reply with content-encoding header; get an uncompressed response."),
{200, Headers, Body} = do_get("/stream_reply/content-encoding",