hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: HttpUriRequest.getURI() returns relative URI?
Date Tue, 07 Dec 2010 12:48:28 GMT
On 7 December 2010 09:35, Oleg Kalnichevski <olegk@apache.org> wrote:
> On Mon, 2010-12-06 at 20:39 +0000, sebb wrote:
>> I'm following the example in the HttpClient documentation:
>>
>>             DefaultHttpClient httpclient = new DefaultHttpClient();
>>             HttpContext localContext = new BasicHttpContext();
>>             HttpGet httpget = new HttpGet("http://www.google.com/");
>>             HttpResponse response = httpclient.execute(httpget, localContext);
>>             HttpHost target = (HttpHost) localContext.getAttribute(
>>                     ExecutionContext.HTTP_TARGET_HOST);
>>             HttpUriRequest req = (HttpUriRequest) localContext.getAttribute(
>>                     ExecutionContext.HTTP_REQUEST);
>>             System.out.println("Target host: " + target);
>>             System.out.println("Final request URI: " + req.getURI());
>>
>> I see the following output:
>>
>> Target host: http://www.google.co.uk
>> Final request URI: /
>>
>> However, I would expect to see an absolute URI, as per the Javadoc for
>> HttpUriRequest#getURI().
>>
>> Is this a bug in the Javadoc (and user guide?) or a bug in the code?
>>
>
> Hi Sebastian
>
> I could find any passage in javadocs or tutorial stating such
> requirement.

Javadoc for getURI() starts:

    /**
     * Returns the URI this request uses, such as
     * <code>http://example.org/path/to/file</code>.
     *

which strongly suggests that the URI is absolute.

Also, section 1.1.1 has 2 examples which display absolute URIs.

I've not found an example which shows a relative URI.

> As far as I remember request URIs can be either absolute or
> relative.

AFAICT, this is not documented.

> In case of a relative request URI HttpClient attempts to
> determine the target host based on request parameters. In case of a
> absolute request URI HttpClient rewrites the request URI as relative and
> adds a 'Host' header containing the target host.

Seems to me that user code is often going to need the absolute URI of
the request, so there should be a method to return the absolute URI.

It's confusing that the URI returned from the execution context
appears to be always relative, even if the original request uses an
absolute URI.

Combining the first example in section 1.1.1 with the execution
context example in section 5.4 produces the following output:

http://www.google.com/search?q=httpclient&btnG=Google+Search&aq=f&oq=
Target host: http://www.google.com
Final request URI: /search?q=httpclient&btnG=Google+Search&aq=f&oq=


> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

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


Mime
View raw message