Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add request header within DefaultRedirectHandler.getLocationURI callback

I have the following scenario:

Android HttpClient is redirected to alternative location, the redirection url comes back with a certain url parameter which has to be propagated as extra http header in the redirection request. The only way to interfere is to override the DefaultRedirectHandler.getLocationURI handler. Now my question: how within

public URI getLocationURI(HttpResponse response, HttpContext context)

I can modify the out-coming request.

like image 349
Denis Voloshin Avatar asked Jul 19 '26 06:07

Denis Voloshin


1 Answers

You have to create an implementation of RedirectHandler and overwrite getLocationURI(). You can get the redirect url by

    Header locationHeader = response.getFirstHeader("location");
    String location = locationHeader.getValue();

extract your url parameter from location and then you could get the HttpRequest by

    BasicHttpRequest request = (BasicHttpRequest) context.getAttribute(
                            ExecutionContext.HTTP_REQUEST);
    header.addHeader();
like image 89
Thilak Avatar answered Jul 20 '26 18:07

Thilak