On 7 December 2010 12:48, sebb <[email protected]> wrote: > On 7 December 2010 09:35, Oleg Kalnichevski <[email protected]> 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=
Just to be clear - I don't have a problem with the current implementation. However, I do think the documentation needs to be clarified, which I'm happy to do. > >> Oleg >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
