Skip to content

Commit e7b6e2a

Browse files
David KellyLoïc Hoguin
authored andcommitted
Added absoluteURI support
If requests go through a proxy, they will have the original uri in the request, i.e. : GET http://proxy.server.uri/some/query/string HTTP 1.1 ... That was problematic -- cowboy_http_protocol:request didn't know what to to with the result of decode_packet applied to this, which would be something like: ``` erlang {http_request,'GET',{absoluteURI,http,<<"proxy.server.uri">>, undefined,<<"/some/query/string">>},{1,1}} ``` So, I just ignore the host, grab the path and pass into ``` erlang cowboy_http_protocol:request({http_request, Method, {abs_path, Path}, Version}, State) ``` Seems to do the trick without much effort.
1 parent 062db95 commit e7b6e2a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/cowboy_http_protocol.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ wait_request(State=#state{socket=Socket, transport=Transport,
113113
request({http_request, _Method, _URI, Version}, State)
114114
when Version =/= {1, 0}, Version =/= {1, 1} ->
115115
error_terminate(505, State);
116+
%% We still receive the original Host header.
117+
request({http_request, Method, {absoluteURI, _Scheme, _Host, _Port, Path},
118+
Version}, State) ->
119+
request({http_request, Method, {abs_path, Path}, Version}, State);
116120
request({http_request, Method, {abs_path, AbsPath}, Version},
117121
State=#state{socket=Socket, transport=Transport,
118122
urldecode={URLDecFun, URLDecArg}=URLDec}) ->

test/http_SUITE.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ raw(Config) ->
378378
{"GET / HTTP/1.1\r\nHost: localhost", 408},
379379
{"GET / HTTP/1.1\r\nHost: localhost\r\n", 408},
380380
{"GET / HTTP/1.1\r\nHost: localhost\r\n\r", 408},
381-
{"GET http://localhost/ HTTP/1.1\r\n\r\n", 501},
381+
{"GET http://proxy/ HTTP/1.1\r\n\r\n", 400},
382+
{"GET http://proxy/ HTTP/1.1\r\nHost: localhost\r\n\r\n", 200},
382383
{"GET / HTTP/1.2\r\nHost: localhost\r\n\r\n", 505},
383384
{"GET /init_shutdown HTTP/1.1\r\nHost: localhost\r\n\r\n", 666},
384385
{"GET /long_polling HTTP/1.1\r\nHost: localhost\r\n\r\n", 102},

0 commit comments

Comments
 (0)