Redirect 302 IllegalArgumentException without workaround java.lang.IllegalArgumentException: Unexpected char 0xf6 at 53 in header value
See original GitHub issueSo say I’m looking for a random reddit post via something like: https://www.reddit.com/r/EarthPorn/random/.json
And I get a 302 redirect to something like: https://www.reddit.com/r/EarthPorn/comments/3viwq1/mjölkeviken_sweden_3246x2448_oc/.json which gets stored in the “Location” header.
Notice the umlaut. It causes the IllegalArgumentException.
So I see that this was announced as part of the 2.5 release: “OkHttp now rejects request headers that contain invalid characters”. And I think that is good as default behavior but it would be nice to be able to sanitize the headers before the request chain is errored out completely.
I can’t use a network interceptor to solve this problem:
client.networkInterceptors().add(object : Interceptor {
override fun intercept(chain: Interceptor.Chain?): Response? {
var req = chain?.request()
//The request headers are all valid
return chain?.proceed(req)?.let { //BOOM!!! The crash happens in proceed
//This is where we would fix the headers if we could
it
}
}
})
My stack trace looks like:
fail
java.lang.IllegalArgumentException: Unexpected char 0xf6 at 53 in header value: https://www.reddit.com/r/EarthPorn/comments/3viwq1/mjölkeviken_sweden_3246x2448_oc/.json
at com.squareup.okhttp.Headers$Builder.checkNameAndValue(Headers.java:295)
at com.squareup.okhttp.Headers$Builder.add(Headers.java:245)
at com.squareup.okhttp.internal.http.FramedTransport.readSpdy3HeadersList(FramedTransport.java:229)
at com.squareup.okhttp.internal.http.FramedTransport.readResponseHeaders(FramedTransport.java:142)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:909)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:93)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:894)
at com.hotpodata.baconforkotlin.RedditSessionService$genService$1.intercept(RedditSessionService.kt:73)
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
okhttp: IllegalArgumentException: Unexpected char 0xea
We can use addUnsafeNonAscii to solve this issue. Below is the simple code snippet of it. Headers headers = new Headers.Builder() .
Read more >Diff - 6912887bc9c4dfc560998cfdb6a7b1ce6d629417^2 ...
Libcore.os.stat(parent).st_uid) { + throw new IllegalArgumentException("Optimized data directory " + parent + + " is not owned by the current user.
Read more >HttpClient exception unexpected char in header value - MSDN
This appears to be affecting just some Android Oreo and Pie devices but it prevents all calls from completing without exception. We do...
Read more >aarch32-port/jdk8u/jdk: 837459e35625 - Java.net
src/share/classes/java/lang/invoke/LambdaFormEditor.java, 4 ... + * @throws IllegalArgumentException if <tt>outputFile</tt> does not end with ".hprof" ...
Read more >Active Campaign Exploits Critical Apache Struts 2 Flaw in the ...
They added, “considering it's only been two weeks since this vulnerability was discovered, it's worth noting how fast attackers are weaponizing ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yup, real problem. Will fix.
Fixed by: https://github.com/square/okhttp/pull/2587