mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Send a 426 when Websocket is required and client didn't upgrade
This commit is contained in:
parent
5269bf580b
commit
c2b813684e
2 changed files with 46 additions and 13 deletions
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue