Skip to content

Commit

Permalink
Ignore client_max_window_bits with missing header
Browse files Browse the repository at this point in the history
When the client does not provide the "client_max_window_bits" option,
the server must reserve the max size.

Co-authored-by: Ignacio Martínez <[email protected]>
  • Loading branch information
Kuroneer and imrivera committed Oct 5, 2021
1 parent 0f5c2f8 commit 5990041
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cow_ws.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ negotiate_permessage_deflate1(Params, Extensions, Opts) ->
_ -> [<<"; server_max_window_bits=">>,
integer_to_binary(ServerMaxWindowBits)|RespParams2]
end,
NegotiatedClientMaxWindowBits = case Negotiated of
#{client_max_window_bits_set := true} ->
maps:get(client_max_window_bits, Negotiated);
_ ->
15
end,
{Inflate, Deflate} = init_permessage_deflate(
maps:get(client_max_window_bits, Negotiated),
NegotiatedClientMaxWindowBits,
maps:get(server_max_window_bits, Negotiated), Opts),
{ok, [<<"permessage-deflate">>, RespParams], Extensions#{
deflate => Deflate,
Expand All @@ -165,12 +171,14 @@ negotiate_params([{<<"client_max_window_bits">>, Max}|Tail], Negotiated, RespPar
error ->
ignore;
CB when CB =< CB0 ->
negotiate_params(Tail, Negotiated#{client_max_window_bits => CB},
negotiate_params(Tail,
Negotiated#{client_max_window_bits => CB,
client_max_window_bits_set => true},
[<<"; client_max_window_bits=">>, Max|RespParams]);
%% When the client sends window bits larger than the server wants
%% to use, we use what the server defined.
_ ->
negotiate_params(Tail, Negotiated,
negotiate_params(Tail, Negotiated#{client_max_window_bits_set => true},
[<<"; client_max_window_bits=">>, integer_to_binary(CB0)|RespParams])
end;
negotiate_params([{<<"server_max_window_bits">>, Max}|Tail], Negotiated, RespParams) ->
Expand Down

0 comments on commit 5990041

Please sign in to comment.