aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-30 16:21:25 +0000
committerLoïc Hoguin <[email protected]>2017-10-30 16:21:25 +0000
commit217fac7f4414f5ff5eda85079a179e2462aba61c (patch)
tree9493f8a7df840ffb9d971ec3015aeb0586e9aae4 /test
parentf3d6b05b863fe177a34a8a6ba48c5f263ef8cf82 (diff)
downloadcowboy-217fac7f4414f5ff5eda85079a179e2462aba61c.tar.gz
cowboy-217fac7f4414f5ff5eda85079a179e2462aba61c.tar.bz2
cowboy-217fac7f4414f5ff5eda85079a179e2462aba61c.zip
Handle expect: 100-continue request headers
The 100 continue response will only be sent if the client has not sent the body yet (at all), if the connection is HTTP/1.1 or above and if the user has not sent it yet. The 100 continue response is sent when the user calls read_body and it is cowboy_stream_h's responsibility to send it. This means projects that don't use the cowboy_stream_h stream handler will need to handle the expect header themselves (but that's okay because they might have different considerations than normal Cowboy).
Diffstat (limited to 'test')
-rw-r--r--test/handlers/echo_h.erl3
-rw-r--r--test/req_SUITE.erl28
2 files changed, 31 insertions, 0 deletions
diff --git a/test/handlers/echo_h.erl b/test/handlers/echo_h.erl
index b7a407b..18bdbe6 100644
--- a/test/handlers/echo_h.erl
+++ b/test/handlers/echo_h.erl
@@ -18,6 +18,9 @@ echo(<<"read_body">>, Req0, Opts) ->
_ -> ok
end,
{_, Body, Req} = case cowboy_req:path(Req0) of
+ <<"/100-continue", _/bits>> ->
+ cowboy_req:inform(100, Req0),
+ cowboy_req:read_body(Req0);
<<"/full", _/bits>> -> read_body(Req0, <<>>);
<<"/opts", _/bits>> -> cowboy_req:read_body(Req0, Opts);
_ -> cowboy_req:read_body(Req0)
diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl
index 2d1fe38..107cdd8 100644
--- a/test/req_SUITE.erl
+++ b/test/req_SUITE.erl
@@ -54,6 +54,7 @@ init_dispatch(Config) ->
{"/opts/:key/length", echo_h, #{length => 1000}},
{"/opts/:key/period", echo_h, #{length => 999999999, period => 1000}},
{"/opts/:key/timeout", echo_h, #{timeout => 1000, crash => true}},
+ {"/100-continue/:key", echo_h, []},
{"/full/:key", echo_h, []},
{"/no/:key", echo_h, []},
{"/direct/:key/[...]", echo_h, []},
@@ -456,6 +457,33 @@ do_read_body_timeout(Path, Body, Config) ->
{response, _, 500, _} = gun:await(ConnPid, Ref),
gun:close(ConnPid).
+read_body_expect_100_continue(Config) ->
+ doc("Request body with a 100-continue expect header."),
+ do_read_body_expect_100_continue("/read_body", Config).
+
+read_body_expect_100_continue_user_sent(Config) ->
+ doc("Request body with a 100-continue expect header, 100 response sent by handler."),
+ do_read_body_expect_100_continue("/100-continue/read_body", Config).
+
+do_read_body_expect_100_continue(Path, Config) ->
+ ConnPid = gun_open(Config),
+ Body = <<0:8000000>>,
+ Headers = [
+ {<<"accept-encoding">>, <<"gzip">>},
+ {<<"expect">>, <<"100-continue">>},
+ {<<"content-length">>, integer_to_binary(byte_size(Body))}
+ ],
+ Ref = gun:post(ConnPid, Path, Headers),
+ {inform, 100, []} = gun:await(ConnPid, Ref),
+ gun:data(ConnPid, Ref, fin, Body),
+ {response, IsFin, 200, RespHeaders} = gun:await(ConnPid, Ref),
+ {ok, RespBody} = case IsFin of
+ nofin -> gun:await_body(ConnPid, Ref);
+ fin -> {ok, <<>>}
+ end,
+ gun:close(ConnPid),
+ do_decode(RespHeaders, RespBody).
+
read_urlencoded_body(Config) ->
doc("application/x-www-form-urlencoded request body."),
<<"[]">> = do_body("POST", "/read_urlencoded_body", [], <<>>, Config),