You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Stuart White <st...@gmail.com> on 2008/12/17 20:34:46 UTC

HttpUriRequest.getURI() inconsistent behavior?

The behavior of HttpUriRequest.getURI() seems to be inconsistent,
depending on whether the request goes through a proxy or not.

For this example, I'm attempting to access http://zeroc.com/download.html.

Please see the attached source code.  If I run this source code with
no proxy configured, getURI() returns:

/download.html

However, if I change the code to use a proxy, getURI() now returns:

http://zeroc.com/download.html

I've tested this both with the latest releases of httpcore and
httpclient as well as subversion revision 727427, and this behavior
occurs regardless.

Is this expected behavior?  Thanks!


Re: HttpUriRequest.getURI() inconsistent behavior?

Posted by Oleg Kalnichevski <ol...@apache.org>.
Stuart White wrote:
> Then what is the appropriate way for me to determine where a request
> was redirected to, regardless of whether it went through a proxy?
> Thanks!
> 

Here's what you do:

private static URI getLocation(HttpContext context)
   throws URISyntaxException {
     HttpUriRequest finalRequest = (HttpUriRequest) context
             .getAttribute(ExecutionContext.HTTP_REQUEST);
     HttpHost target = (HttpHost) context
             .getAttribute(ExecutionContext.HTTP_TARGET_HOST);
     URI uri = finalRequest.getURI();
     if (!uri.isAbsolute()) {
         uri = URIUtils.rewriteURI(uri, target);
     }
     return uri;
}



> On Fri, Dec 19, 2008 at 7:51 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>> On Wed, 2008-12-17 at 13:34 -0600, Stuart White wrote:
>>> The behavior of HttpUriRequest.getURI() seems to be inconsistent,
>>> depending on whether the request goes through a proxy or not.
>>>
>>> For this example, I'm attempting to access http://zeroc.com/download.html.
>>>
>>> Please see the attached source code.  If I run this source code with
>>> no proxy configured, getURI() returns:
>>>
>>> /download.html
>>>
>>> However, if I change the code to use a proxy, getURI() now returns:
>>>
>>> http://zeroc.com/download.html
>>>
>>> I've tested this both with the latest releases of httpcore and
>>> httpclient as well as subversion revision 727427, and this behavior
>>> occurs regardless.
>>>
>>> Is this expected behavior?
>> Yes, it is. The URI of the request object corresponds to the Request-URI
>> of the HTTP message. It is expected to be relative for direct requests
>> and absolute for proxied ones.
>>
>> Hope this helps
>>
>> Oleg
>>
>>
>>>  Thanks!
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: HttpUriRequest.getURI() inconsistent behavior?

Posted by Stuart White <st...@gmail.com>.
Then what is the appropriate way for me to determine where a request
was redirected to, regardless of whether it went through a proxy?
Thanks!

On Fri, Dec 19, 2008 at 7:51 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Wed, 2008-12-17 at 13:34 -0600, Stuart White wrote:
>> The behavior of HttpUriRequest.getURI() seems to be inconsistent,
>> depending on whether the request goes through a proxy or not.
>>
>> For this example, I'm attempting to access http://zeroc.com/download.html.
>>
>> Please see the attached source code.  If I run this source code with
>> no proxy configured, getURI() returns:
>>
>> /download.html
>>
>> However, if I change the code to use a proxy, getURI() now returns:
>>
>> http://zeroc.com/download.html
>>
>> I've tested this both with the latest releases of httpcore and
>> httpclient as well as subversion revision 727427, and this behavior
>> occurs regardless.
>>
>> Is this expected behavior?
>
> Yes, it is. The URI of the request object corresponds to the Request-URI
> of the HTTP message. It is expected to be relative for direct requests
> and absolute for proxied ones.
>
> Hope this helps
>
> Oleg
>
>
>>  Thanks!
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: HttpUriRequest.getURI() inconsistent behavior?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-12-17 at 13:34 -0600, Stuart White wrote:
> The behavior of HttpUriRequest.getURI() seems to be inconsistent,
> depending on whether the request goes through a proxy or not.
> 
> For this example, I'm attempting to access http://zeroc.com/download.html.
> 
> Please see the attached source code.  If I run this source code with
> no proxy configured, getURI() returns:
> 
> /download.html
> 
> However, if I change the code to use a proxy, getURI() now returns:
> 
> http://zeroc.com/download.html
> 
> I've tested this both with the latest releases of httpcore and
> httpclient as well as subversion revision 727427, and this behavior
> occurs regardless.
> 
> Is this expected behavior? 

Yes, it is. The URI of the request object corresponds to the Request-URI
of the HTTP message. It is expected to be relative for direct requests
and absolute for proxied ones.

Hope this helps

Oleg   


>  Thanks!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org