Android volley to handle redirect
android, android-volley
Solution
I fixed it catching the http status 301 or 302, reading redirect url and setting it to request then throwing expection which triggers retry.
Edit: Here are the main keys in volley lib which i modified:
Added method public void `setUrl(final String url)` for class `Request`
In class BasicNetwork is added check for redirection after // Handle cache validation, `if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY) || statusCode == HttpStatus.SC_MOVED_TEMPORARILY)`, there I read the redirect url with `responseHeaders.get("location")`, call `setUrl` with request object and throw error
Error get's catched and it calls `attemptRetryOnException`
You also need to have `RetryPolicy` set for the `Request` (see `DefaultRetryPolicy` for this)
Problem
I recently started to use Volley lib from Google for my network requests. One of my requests get error 301 for redirect, so my question is that can volley handle redirect somehow automatically or do I have to handle it manually in `parseNetworkError` or use some kind of `RetryPolicy`here? Thanks.