Skip to content

Commit

Permalink
Handle URLs where the query part follows the hostname without a slash…
Browse files Browse the repository at this point in the history
… in between

For example, in http://www.example.com?a=b the hostname is
"www.example.com", not "www.example.com?a=b".  See RFC 3986, section 3.
  • Loading branch information
legoscia committed Jan 28, 2013
1 parent abf356e commit 801c902
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/lhttpc_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ split_host([$: | PortPath], Host) ->
{lists:reverse(Host), PortPath};
split_host([$/ | _] = PortPath, Host) ->
{lists:reverse(Host), PortPath};
split_host([$? | _] = Query, Host) ->
%% The query string follows the hostname, without a slash. The
%% path is empty, but for HTTP an empty path is equivalent to "/"
%% (RFC 3986, section 6.2.3), so let's add the slash ourselves.
{lists:reverse(Host), "/" ++ Query};
split_host([H | T], Host) ->
split_host(T, [H | Host]);
split_host([], Host) ->
Expand Down
12 changes: 11 additions & 1 deletion test/lhttpc_lib_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,15 @@ parse_url_test_() ->
user = "joe",
password = "erlang"
},
lhttpc_lib:parse_url("http://joe:erlang@[1080:0:0:0:8:800:200C:417A]:180/foo/bar"))
lhttpc_lib:parse_url("http://joe:erlang@[1080:0:0:0:8:800:200C:417A]:180/foo/bar")),

?_assertEqual(#lhttpc_url{
host = "www.example.com",
port = 80,
path = "/?a=b",
is_ssl = false,
user = "",
password = ""
},
lhttpc_lib:parse_url("http://www.example.com?a=b"))
].

0 comments on commit 801c902

Please sign in to comment.