New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complies with rfc7231 about statuses 307 and 308 #5990
Conversation
Author: Vladimir Kravets <vova.kravets@gmail.com>
@swankjesse Any thoughts on how to implement the interceptor? The logic sits between interceptors, and networkInterceptors. So seems like we would need to tag requests in interceptors such that the RetryAndFollowupInterceptor doesn't retry for these? Or put this as a field like client.retryOnConnectionFailure. |
I was thinking something much more basic. Maybe the interceptor would rewrite 308s to a bogus code like 399 to get the previous behavior. |
That feels tough to explain if you see that code elsewhere like another interceptor. |
The more I think about this, the more I think we should just follow the correct logic and leave reverting to the old behaviour to users affected by this. But with heavy notification and a suggestion for how users could revert to the previous behaviour, e.g. implement your own interceptor that rewrites the response code. Under what scenarios would mobile clients want the old behaviour? And shouldn't we encourage clients and servers move towards the correct defined behaviour? An API server is likely to only have okhttp as the only mobile client transport. So definitely not a client flag. A new public API as a workaround interceptor feels like a bad public API also. |
Oh I was thinking the interceptor would be a code sample you'd gave to copy-paste. |
Perfect |
I hope noone ever uses this
|
@swankjesse Is this for 4.6? |
@@ -2367,6 +2370,71 @@ private void testResponseRedirectedWithPost(int redirectCode, TransferKind trans | |||
testRedirect(false, "POST"); | |||
} | |||
|
|||
class RevertInterceptor implements Interceptor { | |||
@NotNull @Override public Response intercept(@NotNull Chain chain) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we don’t typically use @NotNull
because everything is not null unless otherwise specified
} | ||
|
||
private Response remapResponse(Response response) { | ||
if (response.request().method().equals("POST") && (response.code() == HTTP_TEMP_REDIRECT || response.code() == HTTP_PERM_REDIRECT)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this should probably be checking for not GET and not HEAD, otherwise PUT isn‘t consistent!
…, okhttp only follows them starting version 4.6.0 (square/okhttp#5990) Ignored findbugs issues, since null was always a valid return value anyhow.
Fix for #2874 #3111 and #4229
https://tools.ietf.org/html/rfc7231#page-58
https://tools.ietf.org/html/rfc7238