0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 13:10:24 +00:00

Pass the HTTP/2 switch_protocol event to stream handlers

To accomplish this the code for sending the 101 response was
moved to the cowboy_http2 module.
This commit is contained in:
Loïc Hoguin 2017-04-18 14:06:34 +02:00
parent 3633bceac5
commit 6e8b907ae2
No known key found for this signature in database
GPG key ID: 71366FF21851DF03
3 changed files with 26 additions and 15 deletions

View file

@ -635,6 +635,7 @@ request(Buffer, State0=#state{ref=Ref, transport=Transport, peer=Peer, in_stream
%% HTTP/2 upgrade.
%% @todo We must not upgrade to h2c over a TLS connection.
is_http2_upgrade(#{<<"connection">> := Conn, <<"upgrade">> := Upgrade,
<<"http2-settings">> := HTTP2Settings}, 'HTTP/1.1') ->
Conns = cow_http_hd:parse_connection(Conn),
@ -675,13 +676,6 @@ http2_upgrade(State=#state{parent=Parent, ref=Ref, socket=Socket, transport=Tran
%% Always half-closed stream coming from this side.
try cow_http_hd:parse_http2_settings(HTTP2Settings) of
Settings ->
%% @todo We should invoke cowboy_stream:info for this stream,
%% with a switch_protocol tuple.
Transport:send(Socket, cow_http:response(101, 'HTTP/1.1', maps:to_list(#{
<<"connection">> => <<"Upgrade">>,
<<"upgrade">> => <<"h2c">>
}))),
%% @todo Possibly redirect the request if it was https.
_ = cancel_request_timeout(State),
cowboy_http2:init(Parent, Ref, Socket, Transport, Opts, Peer, Buffer, Settings, Req)
catch _:_ ->