http:request/4 proxy redirection problem

Anton Berezin <>
Mon Jul 31 20:26:41 CEST 2006


Hi,

It appears that when one uses http:request/4 with a configured proxy, and
the webserver returns 3XX code, http:request/4 enters an endless loop.

There seems to be two problems in fact:

First, the guard statement that checks for HTTP_MAX_REDIRECTS to prevent
looping is written as Code / 100 == 3, which does not quite do what it
should, so redirection loops are not detected.

Secondly, when httpc_response:redirect/2 constructs a new request, it
does not update #request.abs_uri, which in fact is the only thing that
is used by the proxy branch of the code when making the request.

A patch follows.  The last chunk of the patch is a quick hack.  My
Erlang knowledge is rather embryonic, and I could not find the opposite
to http_uri:parse/1 anywhere.

If this is already fixed in unreleased version of inets, sorry for
wasting everybody's time.

--- lib/inets-4.7.4/src/httpc_response.erl	Wed May  3 10:22:37 2006
+++ lib/inets-4.7.4/src/httpc_response.erl	Mon Jul 31 20:13:09 2006
@@ -84,7 +84,7 @@ result(Response = {{_,100,_}, _, _}, Req
 result(Response = {{_, Code, _}, _, _}, Request =
        #request{redircount = Redirects,
 		settings = #http_options{autoredirect = true}}) 
-  when Code / 100 == 3, Redirects > ?HTTP_MAX_REDIRECTS ->
+  when Code div 100 == 3, Redirects > ?HTTP_MAX_REDIRECTS ->
     transparent(Response, Request);
 
 %% multiple choices or use proxy
@@ -114,7 +114,7 @@ result(Response = {{_, Code, _}, _, _}, 
 
 result(Response = {{_,503,_}, _, _}, Request) ->
     status_service_unavailable(Response, Request);
-result(Response = {{_,Code,_}, _, _}, Request) when (Code / 100) == 5 ->
+result(Response = {{_,Code,_}, _, _}, Request) when (Code div 100) == 5 ->
     status_server_error_50x(Response, Request);
 
 result(Response, Request) -> 
@@ -247,7 +247,11 @@ redirect(Response = {StatusLine, Headers
 					headers = NewHeaders,
 					address = {Host,Port},
 					path = Path,
-					pquery = Query},
+					pquery = Query,
+					abs_uri =
+						atom_to_list(Scheme)++"://"++
+						Host++":"++integer_to_list(Port)++
+						Path++Query},
 		    {redirect, NewRequest, Data}
 	    end
     end.


\Anton.
-- 
We're going for 'working' here.
'Clean' is for people with skills...  -- Flemming Jacobsen



More information about the erlang-questions mailing list