Skip to content

Commit 0a82022

Browse files
author
Patrick Sachs
committed
Fixed: Error when replying to an HTTPS/2 request that was proxied to an HTTP/1.1 server
This was caused by Cowboy requiring the response headers to be in binary for HTTPS/2, but the response headers for an HTTP/1.1 request are strings/charlists.
1 parent 758e934 commit 0a82022

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/cowboy_reverse_proxy.erl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ init(Req0, State) ->
9393
response_headers({{RespVersion, RespStatus, RespReason}, RespHeaders, _RespBody}, Opts) ->
9494
List = case opts_disable_proxy_headers(Opts) of
9595
true ->
96-
RespHeaders;
96+
tuple_list_to_binary(RespHeaders);
9797
false ->
9898
[
99-
{"x-proxy-http-version", RespVersion},
100-
{"x-proxy-status", to_string(RespStatus)},
101-
{"x-proxy-reason", to_string(RespReason)}
102-
| RespHeaders
99+
{<<"x-proxy-http-version">>, RespVersion},
100+
{<<"x-proxy-status">>, to_string(RespStatus)},
101+
{<<"x-proxy-reason">>, to_string(RespReason)}
102+
| tuple_list_to_binary(RespHeaders)
103103
]
104104
end,
105105
maps:from_list(List).
@@ -210,6 +210,14 @@ to_string(Int) when is_integer(Int) -> integer_to_list(Int);
210210
to_string(Binary) when is_binary(Binary) -> binary_to_list(Binary);
211211
to_string(List) -> binary_to_list(iolist_to_binary(List)).
212212

213+
%% Any string to a binary
214+
to_binary(Binary) when is_binary(Binary) -> Binary;
215+
to_binary(List) -> iolist_to_binary(List).
216+
217+
%% Converts all keys in to binary
218+
tuple_list_to_binary(List) ->
219+
[{to_binary(Key), to_binary(Value)} || {Key, Value} <- List].
220+
213221
%% Dumps any term into a string representation.
214222
dump(Term) ->
215223
to_string(io_lib:format("~p", [Term])).

0 commit comments

Comments
 (0)