diff options
author | Loïc Hoguin <[email protected]> | 2019-10-03 11:51:14 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-10-03 11:51:14 +0200 |
commit | 6a4f901c7938a070cf7a80fdb366e17f8a300aff (patch) | |
tree | 177a1eb997ebc2b69cf433e86b1b58652f91d087 /src | |
parent | cdb2efc23fe18c365367c0e614186d9924e66a9e (diff) | |
download | cowlib-6a4f901c7938a070cf7a80fdb366e17f8a300aff.tar.gz cowlib-6a4f901c7938a070cf7a80fdb366e17f8a300aff.tar.bz2 cowlib-6a4f901c7938a070cf7a80fdb366e17f8a300aff.zip |
Remove HTTP/1.1 connection headers in HTTP/2 messages
Diffstat (limited to 'src')
-rw-r--r-- | src/cow_http2_machine.erl | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/cow_http2_machine.erl b/src/cow_http2_machine.erl index 38cfdc9..68d361a 100644 --- a/src/cow_http2_machine.erl +++ b/src/cow_http2_machine.erl @@ -1079,7 +1079,6 @@ timeout(_, _, State) -> -spec prepare_headers(cow_http2:streamid(), State, idle | cow_http2:fin(), pseudo_headers(), cow_http:headers()) -> {ok, cow_http2:fin(), iodata(), State} when State::http2_machine(). -%% @todo Should handle the request case too. prepare_headers(StreamID, State=#http2_machine{encode_state=EncodeState0}, IsFin0, PseudoHeaders, Headers0) -> Stream = #stream{method=Method, local=idle} = stream_get(StreamID, State), @@ -1088,7 +1087,7 @@ prepare_headers(StreamID, State=#http2_machine{encode_state=EncodeState0}, {_, <<"HEAD">>} -> fin; _ -> IsFin0 end, - Headers = merge_pseudo_headers(PseudoHeaders, Headers0), + Headers = merge_pseudo_headers(PseudoHeaders, remove_http11_headers(Headers0)), {HeaderBlock, EncodeState} = cow_hpack:encode(Headers, EncodeState0), {ok, IsFin, HeaderBlock, stream_store(Stream#stream{local=IsFin0}, State#http2_machine{encode_state=EncodeState})}. @@ -1107,7 +1106,7 @@ prepare_push_promise(StreamID, State=#http2_machine{encode_state=EncodeState0, {_, TE0} -> TE0; false -> undefined end, - Headers = merge_pseudo_headers(PseudoHeaders, Headers0), + Headers = merge_pseudo_headers(PseudoHeaders, remove_http11_headers(Headers0)), {HeaderBlock, EncodeState} = cow_hpack:encode(Headers, EncodeState0), {ok, LocalStreamID, HeaderBlock, stream_store( #stream{id=LocalStreamID, method=maps:get(method, PseudoHeaders), @@ -1115,6 +1114,26 @@ prepare_push_promise(StreamID, State=#http2_machine{encode_state=EncodeState0, local_window=LocalWindow, remote_window=RemoteWindow, te=TE}, State#http2_machine{encode_state=EncodeState, local_streamid=LocalStreamID + 2})}. +remove_http11_headers(Headers) -> + RemoveHeaders0 = [ + <<"keep-alive">>, + <<"proxy-connection">>, + <<"transfer-encoding">>, + <<"upgrade">> + ], + RemoveHeaders = case lists:keyfind(<<"connection">>, 1, Headers) of + false -> + RemoveHeaders0; + {_, ConnHd} -> + %% We do not need to worry about any "close" header because + %% that header name is reserved. + Connection = cow_http_hd:parse_connection(ConnHd), + Connection ++ [<<"connection">>|RemoveHeaders0] + end, + lists:filter(fun({Name, _}) -> + not lists:member(Name, RemoveHeaders) + end, Headers). + merge_pseudo_headers(PseudoHeaders, Headers0) -> lists:foldl(fun ({status, Status}, Acc) when is_integer(Status) -> |