Note that there are some explanatory texts on larger screens.

plurals
  1. POHeaders overwritten on redirect using Apache HttpComponents
    primarykey
    data
    text
    <p>I'm using Apache HttpComponents (core - 4.1.3, httpclient 4.1.1) to make http requests in a REST client I've written. The web service requires OAuth, which I've implemented using signpost. Recently, the webservice has introduced 301 redirects to endpoints that also require oauth. So, I've implemented a custom RedirectStrategy which builds a new request and signs it with signpost, just like I would do normally. However, the first two lines (in <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/DefaultRequestDirector.html" rel="nofollow">DefaultRequestDirector</a>) immediately after I return my new request are setting all the headers to those that were sent in the initial request, effectively wiping my new Authorization header and causing all redirect requests to fail.</p> <p>Does anyone know a way around this? I've considered always returning false in my custom <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/RedirectStrategy.html" rel="nofollow">RedirectStrategy</a> and handing this in the <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/ResponseHandler.html" rel="nofollow">ResponseHandler</a> that I've attached to my request, but there's no trivial way of reconstructing the request and submitting it back through the proper client.</p> <p>These are lines 1021-1023 in the DefaultRequestDirector where it calls to my custom RedirectStrategy and then wipes my headers (I'll try to link to source, shortly):</p> <pre><code>HttpUriRequest redirect = redirectStrategy.getRedirect(request, response, context); HttpRequest orig = request.getOriginal(); redirect.setHeaders(orig.getAllHeaders()); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload