From 217fac7f4414f5ff5eda85079a179e2462aba61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 30 Oct 2017 16:21:25 +0000 Subject: 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). --- test/req_SUITE.erl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/req_SUITE.erl') 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), -- cgit v1.2.3