Fuel: 301/302 redirect response data is discarded

Created on 12 Jan 2017  路  5Comments  路  Source: kittinunf/fuel

When Fuel gets a 301/302 redirect response it is handled by the redirectResponseInterceptor. The interceptor immediately accesses the redirect url discarding the initial response. In my case there is valuable data in the redirect location string (auth token). Is there any way to change the redirectResponseInterceptor handler, get a redirect response data or add a new interceptor into the chain before it?

As far as i know, one can only add request and response interceptors.

feature help wanted

Most helpful comment

I would say that your valuable data might be valuable to others as well. Why not fix the original redirectInterceptor to bundle what you need as well?

Also we should allow user to delete item one by one. How about add API to remove specific interceptors from the list?

All 5 comments

If Anyone interested.
After playing around with sources a bit i've found out that removeAllResponseInterceptors removes all interceptors. Not shure if it was made intentionally considering that interceptors` lists are private and redirectInterceptor is created by default.

So what i've done:

var fm = FuelManager.instance
fm.removeAllResponseInterceptors()
fm.addResponseInterceptor(
{ next: (Request, Response) -> Response ->
    { request: Request, response: Response ->
        if (response.httpStatusCode == HttpsURLConnection.HTTP_MOVED_PERM ||
                response.httpStatusCode == HttpsURLConnection.HTTP_MOVED_TEMP) {
                    response
                }
                else
                    next(request, response)
            }
        }
)

This is basically the default redirect interceptor with the redirection code itself removed.
It allows you to get the redirect response as-is without following the link in the "location".

Ah thanks. Would you mind create a PR to fix it?

Sure no problem. But what would you want me to do exatctly?

  1. Fix removeAllResponseInterceptors so it will not delete the default redirectInterceptor implementation?
    But by doing this i will not be able to retrieve my valuable data from the redirect response. In this case i'd suggest adding httpRedirectHeaders map to Response class to keep this data. Is it ok?
  2. Describe this hack in the readme.md

I would say that your valuable data might be valuable to others as well. Why not fix the original redirectInterceptor to bundle what you need as well?

Also we should allow user to delete item one by one. How about add API to remove specific interceptors from the list?

This should be fixed with the latest release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SleeplessByte picture SleeplessByte  路  3Comments

iNoles picture iNoles  路  5Comments

erikthered picture erikthered  路  7Comments

jsyeo picture jsyeo  路  5Comments

milk-machine picture milk-machine  路  6Comments