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/09/26 17:26:23 UTC

[HttpClient trunk] redirect loses request headers

Hi,

when after a redirect response a retry is done by the 
DefaultClientRequestDirector, the RoutedRequest returned by the 
handleResponse method does not contain the request headers from the 
original request. Is this behaviour intended? How can I get the headers 
from the first request into the second? Do I have to add a request 
interceptor?

-- 
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 trunk] redirect loses request headers

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2008-04-22 at 23:46 -0700, Thuannd wrote:
> 
> 
> Johannes Koch-4 wrote:
> > 
> > Hi,
> > 
> > when after a redirect response a retry is done by the 
> > DefaultClientRequestDirector, the RoutedRequest returned by the 
> > handleResponse method does not contain the request headers from the 
> > original request. Is this behaviour intended? How can I get the headers 
> > from the first request into the second? Do I have to add a request 
> > interceptor?
> > 
> > -- 
> > 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
> > 
> > 
> > 
> 
> In "protected RoutedRequest handleResponse(..." method of
> DefaultClientRequestDirector class
> goto line: HttpGet redirect = new HttpGet(uri); 
> then add: redirect.setHeaders(request.getAllHeaders());
> compile httpclient project.

I added similar code to the stock version of HttpClient 4.0. 

Oleg


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


Re: [HttpClient trunk] redirect loses request headers

Posted by Thuannd <nh...@yahoo.com>.


Johannes Koch-4 wrote:
> 
> Hi,
> 
> when after a redirect response a retry is done by the 
> DefaultClientRequestDirector, the RoutedRequest returned by the 
> handleResponse method does not contain the request headers from the 
> original request. Is this behaviour intended? How can I get the headers 
> from the first request into the second? Do I have to add a request 
> interceptor?
> 
> -- 
> 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
> 
> 
> 

In "protected RoutedRequest handleResponse(..." method of
DefaultClientRequestDirector class
goto line: HttpGet redirect = new HttpGet(uri); 
then add: redirect.setHeaders(request.getAllHeaders());
compile httpclient project.
-- 
View this message in context: http://www.nabble.com/-HttpClient-trunk--redirect-loses-request-headers-tp12903389p16832335.html
Sent from the HttpComponents-Dev mailing list archive at Nabble.com.


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


Re: [HttpClient trunk] redirect loses request headers

Posted by Roland Weber <os...@dubioso.net>.
Johannes Koch wrote:

> I tried this. But the headers specified via DEFAULT_HEADERS are only
> added to the original request (orig), not to a subsequent request for
> the redirect.

Please open an issue in JIRA. That's a bug we'll fix.

cheers,
  Roland


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


Re: [HttpClient trunk] redirect loses request headers

Posted by Johannes Koch <jo...@fit.fraunhofer.de>.
Hi Roland,

Roland Weber schrieb:
> Hello Johannes,
> 
>> when after a redirect response a retry is done by the
>> DefaultClientRequestDirector,
> 
> DCRD retries if there is an IO error. In that case, the
> original request is used. If a redirect response is
> received, there is no retry. Redirects are handled by
> creating a new request for the redirect target.

Yep, sorry for mixing terminology. I meant a new request.

>> Do I have to add a request interceptor?
> 
> That is one way. The same request interceptors will be
> applied to the request from your application and to the
> redirected request. You can implement an interceptor
> that adds all headers you want to add to both requests.
> 
> There is also a parameter DEFAULT_HEADERS among the
> client parameter names. It can be set per request if
> necessary. That's probably the easiest way.

I tried this. But the headers specified via DEFAULT_HEADERS are only 
added to the original request (orig), not to a subsequent request for 
the redirect.

> Finally, you could disable automatic redirect handling
> and take care of the redirect in your application. Or
> you could implement a custom ClientRequestDirector.
> Those are the most complex options.

That's what I try to avoid :-)
-- 
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 trunk] redirect loses request headers

Posted by Roland Weber <os...@dubioso.net>.
Hello Johannes,

> when after a redirect response a retry is done by the
> DefaultClientRequestDirector,

DCRD retries if there is an IO error. In that case, the
original request is used. If a redirect response is
received, there is no retry. Redirects are handled by
creating a new request for the redirect target.

> the RoutedRequest returned by the
> handleResponse method does not contain the request headers from the
> original request. Is this behaviour intended?

Yes it is. There is no way to decide which headers
of the original request could be meaningful for the
redirect location.

> How can I get the headers from the first request into the second?

Not at all, but you can add headers to the second request
as you require.

> Do I have to add a request interceptor?

That is one way. The same request interceptors will be
applied to the request from your application and to the
redirected request. You can implement an interceptor
that adds all headers you want to add to both requests.

There is also a parameter DEFAULT_HEADERS among the
client parameter names. It can be set per request if
necessary. That's probably the easiest way.

Finally, you could disable automatic redirect handling
and take care of the redirect in your application. Or
you could implement a custom ClientRequestDirector.
Those are the most complex options.

hope that helps,
  Roland



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