From c2b813684edca59d8b77c33f2632ef243bed7449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 6 Dec 2017 17:31:32 +0100 Subject: Send a 426 when Websocket is required and client didn't upgrade --- test/rfc7231_SUITE.erl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'test/rfc7231_SUITE.erl') diff --git a/test/rfc7231_SUITE.erl b/test/rfc7231_SUITE.erl index f1b3415..9eddf72 100644 --- a/test/rfc7231_SUITE.erl +++ b/test/rfc7231_SUITE.erl @@ -41,7 +41,8 @@ init_dispatch(_) -> {"*", asterisk_h, []}, {"/", hello_h, []}, {"/echo/:key", echo_h, []}, - {"/resp/:key[/:arg]", resp_h, []} + {"/resp/:key[/:arg]", resp_h, []}, + {"/ws", ws_init_h, []} ]}]). %% @todo The documentation should list what methods, headers and status codes @@ -514,6 +515,25 @@ status_code_426(Config) -> {response, _, 426, _} = gun:await(ConnPid, Ref), ok. +status_code_426_upgrade_header(Config) -> + case config(protocol, Config) of + http -> + do_status_code_426_upgrade_header(Config); + http2 -> + doc("HTTP/2 does not support the HTTP/1.1 Upgrade mechanism.") + end. + +do_status_code_426_upgrade_header(Config) -> + doc("A 426 response must include a upgrade header. (RFC7231 6.5.15)"), + ConnPid = gun_open(Config), + Ref = gun:get(ConnPid, "/ws?ok", [ + {<<"accept-encoding">>, <<"gzip">>} + ]), + {response, _, 426, Headers} = gun:await(ConnPid, Ref), + {_, <<"upgrade">>} = lists:keyfind(<<"connection">>, 1, Headers), + {_, <<"websocket">>} = lists:keyfind(<<"upgrade">>, 1, Headers), + ok. + status_code_500(Config) -> doc("The 500 Internal Server Error status code can be sent. (RFC7231 6.6.1)"), ConnPid = gun_open(Config), -- cgit v1.2.3