You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Johannes Koch <jo...@fit.fraunhofer.de> on 2007/10/25 13:33:37 UTC
[HttpClient] Adjusting location URIs
Hi
In org.apache.http.impl.client.DefaultRedirectHandler's getLocationURI
method, the location URI is adjusted if
ClientPNames.REJECT_RELATIVE_REDIRECT is false. However there are 'evil'
cases where the location header value does not start with a '/'. So
the resulting URI looks like
http://www.example.orgfoo.bar
instead of
http://www.example.org/foo.bar
. Do you think, this should also be part of the adjustment?
Something like
String path = uri.getPath().startsWith("/") ? uri.getPath() : "/" +
uri.getPath();
uri = new URI(target.getSchemeName(), null, target.getHostName(),
target.getPort(), path, uri.getQuery(), uri.getFragment());
should do the job.
--
Johannes Koch
BIKA Web Compliance Center - Fraunhofer FIT
Schloss Birlinghoven, D-53757 Sankt Augustin, Germany
Phone: +49-2241-142628 Fax: +49-2241-142065
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: [HttpClient] Adjusting location URIs
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2007-10-25 at 14:54 +0200, Johannes Koch wrote:
> Ortwin Glück schrieb:
> > Johannes Koch wrote:
> >> is a URI where the path component does not start with a '/'. And so I get
> >>
> >> java.net.URISyntaxException: Relative path in absolute URI:
> >> http://www.example.orgfoo.bar
> >
> > Yes, it's currently broken, and your suggested fix would break it even more.
>
> Yes. You suggest
>
> > Instead
> > the resulting URI must be resolved against the request URI
>
> But currently it is not. Instead a new URI is created from the target
> URI scheme, host, port and the location header value.
>
Johannes,
You are right about current logic in the DefaultRedirectHandler being
broken. But I also have to agree with Odi about the proposed solution
not actually improving things that much. Please go ahead and open a JIRA
for this issue. We will also happily accept a patch ;) You just have to
tweak your code a little and take the original request URI into
consideration when resolving the redirect URI.
Cheers
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: [HttpClient] Adjusting location URIs
Posted by Johannes Koch <jo...@fit.fraunhofer.de>.
Ortwin Glück schrieb:
> Johannes Koch wrote:
>> is a URI where the path component does not start with a '/'. And so I get
>>
>> java.net.URISyntaxException: Relative path in absolute URI:
>> http://www.example.orgfoo.bar
>
> Yes, it's currently broken, and your suggested fix would break it even more.
Yes. You suggest
> Instead
> the resulting URI must be resolved against the request URI
But currently it is not. Instead a new URI is created from the target
URI scheme, host, port and the location header value.
--
Johannes Koch
BIKA Web Compliance Center - Fraunhofer FIT
Schloss Birlinghoven, D-53757 Sankt Augustin, Germany
Phone: +49-2241-142628 Fax: +49-2241-142065
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: [HttpClient] Adjusting location URIs
Posted by Ortwin Glück <od...@odi.ch>.
Johannes Koch wrote:
> is a URI where the path component does not start with a '/'. And so I get
>
> java.net.URISyntaxException: Relative path in absolute URI:
> http://www.example.orgfoo.bar
Yes, it's currently broken, and your suggested fix would break it even more.
--
[web] http://www.odi.ch/
[blog] http://www.odi.ch/weblog/
[pgp] key 0x81CF3416
finger print F2B1 B21F F056 D53E 5D79 A5AF 02BE 70F5 81CF 3416
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: [HttpClient] Adjusting location URIs
Posted by Johannes Koch <jo...@fit.fraunhofer.de>.
Hi Ortwin
Ortwin Glück schrieb:
> No, we must not prepend a / as this would change the semantics. Instead
> the resulting URI must be resolved against the request URI:
>
> Request URI = http://www.example.org/a/b/foo.html
> Location: bar.html
>
> => http://www.example.org/a/b/bar.html
>
> versus
>
> Request URI = http://www.example.org/a/b/foo.html
> Location: /bar.html
>
> => http://www.example.org/bar.html
>
> See the URI.resolve method.
But currently with
Location: foo.bar
the result from
uri = new URI(
target.getSchemeName(),
null,
target.getHostName(),
target.getPort(),
uri.getPath(),
uri.getQuery(),
uri.getFragment());
is a URI where the path component does not start with a '/'. And so I get
java.net.URISyntaxException: Relative path in absolute URI:
http://www.example.orgfoo.bar
--
Johannes Koch
BIKA Web Compliance Center - Fraunhofer FIT
Schloss Birlinghoven, D-53757 Sankt Augustin, Germany
Phone: +49-2241-142628 Fax: +49-2241-142065
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: [HttpClient] Adjusting location URIs
Posted by Ortwin Glück <od...@odi.ch>.
Johannes,
No, we must not prepend a / as this would change the semantics. Instead
the resulting URI must be resolved against the request URI:
Request URI = http://www.example.org/a/b/foo.html
Location: bar.html
=> http://www.example.org/a/b/bar.html
versus
Request URI = http://www.example.org/a/b/foo.html
Location: /bar.html
=> http://www.example.org/bar.html
See the URI.resolve method.
Ortwin
Johannes Koch wrote:
> Hi
>
> In org.apache.http.impl.client.DefaultRedirectHandler's getLocationURI
> method, the location URI is adjusted if
> ClientPNames.REJECT_RELATIVE_REDIRECT is false. However there are 'evil'
> cases where the location header value does not start with a '/'. So the
> resulting URI looks like
>
> http://www.example.orgfoo.bar
>
> instead of
>
> http://www.example.org/foo.bar
>
> . Do you think, this should also be part of the adjustment?
>
> Something like
>
> String path = uri.getPath().startsWith("/") ? uri.getPath() : "/" +
> uri.getPath();
> uri = new URI(target.getSchemeName(), null, target.getHostName(),
> target.getPort(), path, uri.getQuery(), uri.getFragment());
>
> should do the job.
--
[web] http://www.odi.ch/
[blog] http://www.odi.ch/weblog/
[pgp] key 0x81CF3416
finger print F2B1 B21F F056 D53E 5D79 A5AF 02BE 70F5 81CF 3416
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org