[
https://issues.apache.org/jira/browse/HTTPCLIENT-1088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Bartosz Firyn closed HTTPCLIENT-1088.
-------------------------------------
Resolution: Not A Problem
Not required.
> Add possibility to alter request headers between redirects
> ----------------------------------------------------------
>
> Key: HTTPCLIENT-1088
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1088
> Project: HttpComponents HttpClient
> Issue Type: Improvement
> Components: HttpClient
> Affects Versions: 4.1.1
> Environment: *
> Reporter: Bartosz Firyn
> Labels: api-change
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> For now there is no possibility to alter headers between consecutive
> redirects. In case when user needs this kind of functionality he has to
> implement his own redirection mechanism from scratch. However this could be
> easily done with standard HTTP client redirection mechanism. I think it is
> worth to add alterHeaders(List<Header> headers) method in the
> DefaultRedirectStrategy class. This method would be called from
> DefaultRequestDirector instead of this code:
> 1023: redirect.setHeaders(orig.getAllHeaders());
> So method I mentioned above would look like - RedirectStrategy:
> Header[] alterHeaders(
> HttpRequest request,
> HttpResponse response,
> HttpRequest redirect,
> Header[] headers);
> Default redirect strategy:
> public Header[] alterHeaders(
> final HttpRequest request,
> final HttpResponse response,
> final HttpRequest redirect,
> final Header[] headers) {
> return headers;
> }
> And call in DefaultRequestDirector like this:
> Header[] headers = orig.getAllHeaders();
> headers = redirectStrategy.alterHeaders(orig, response, redirect,
> headers);
> redirect.setHeaders(headers);
> Why am I asking about this feature? I had a situation when "Host" headers had
> to be changed, but I was not able to do that between redirects. Effect of
> this issue was that I was not able to login to the service I tried to gain
> access to (they check if "Host" header is correctly filled).
> For now easy (and really ugly) workaroud is:
> Create your own redirect strategy impl:
> public class MateRedirectStrategy extends DefaultRedirectStrategy {
> @Override
> public HttpUriRequest getRedirect(HttpRequest request, HttpResponse
> response, HttpContext context) throws ProtocolException {
> // ugly W/A for HTTP Client issue
> HttpUriRequest redirect = super.getRedirect(request, response,
> context);
> URI uri = redirect.getURI();
> String host = uri.getHost();
> ((RequestWrapper) request).getOriginal().setHeader("Host",
> host);
> return redirect;
> }
> }
> And use it in your client:
> client.setRedirectStrategy(new MateRedirectStrategy());
> Thats all.
> Regards
> Bartosz Firyn
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]