[erlang-questions] http client bug in inets when following relative redirects

Elias Torres <>
Sun Feb 8 23:08:27 CET 2009


Here's the example:

[] /usr/local/lib/erlang/lib/inets-5.0.12/src $ erl -s inets

Eshell V5.6.5  (abort with ^G)
1> http:request(get, {"http://mohegansun.com/",[]}, [{autoredirect,
true},{relaxed, true}],[]).
{error,{badarg,[{erlang,'++',[80,"//gateway/index.html"]},
                {httpc_response,fix_relative_uri,2},
                {httpc_response,redirect,2},
                {httpc_handler,handle_response,1},
                {gen_server,handle_msg,5},
                {proc_lib,init_p_do_apply,3}]}}

In httpc_response.erl:fix_relative_uri/2 I found the following:

fix_relative_uri(Request, RedirUrl) ->
    {Server, Port} = Request#request.address,
    Path = Request#request.path,
    atom_to_list(Request#request.scheme) ++ "://" ++ Server ++ ":" ++ Port
	++ Path ++ RedirUrl.

It's choking when concatenating Port which is an integer. For now I
have wrapped Port with an integer_to_list call, but this function
really smells bad. For example, it grabs the original path and simply
concatenates it with the redirect path. In this case "/" +
"/gateway/index.html" == "//gateway/index.html" but what if the
original path was /old_working_link"?

Thanks for you attention to the matter. If there's an official place
to submit this bug please let me know.

-Elias



More information about the erlang-questions mailing list