-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[Android] Allow non-ascii header values & add utf-8 filename fallback #35060
Conversation
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Hi @robertying, Thank you for doing this. We are wondering whether this change could break some webservers that don’t understand the utf8- marker. @dryganets, could you help out with the review? |
@cipolleschi Thanks for taking a look. The detail was discussed in this issue #31537 when I first opened it:
The filtering was done before okhttp fixed the utf-8 thing. Since okhttp has already fixed the utf-8 header value handling, we should remove the workaround that is not invalid anymore. As for whether it will break web servers, this usage is actually included in RFC 5987:
There is also a note:
However, the RFC was written in 2010 and I believe utf-8 support on the server side should be adequate now; and even if the server doesn't understand the extended syntax, it should be able to pick up the original |
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.
The change looks good to me.
The behavior hasn't been handled by okhttp at the moment.
@cipolleschi it seems we could move forward since Sergei has commented. Please let me know if there's anything else that needs addressing! |
@robertying Sorry for the delay, busy days. Can I ask two favours, first:
After that, when the CI is green, I can reimport it! Thank you so much and sorry again for the delay. |
de5ccc9
to
5d31b62
Compare
Base commit: b7a85b5 |
PR build artifact for 5d31b62 is ready. |
Base commit: 92b8981 |
PR build artifact for 33711f2 is ready. |
@cipolleschi No problem! Appreciate the work you've been doing. I fixed some issue and all checks have passed. |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
if (headerName == null || headerValue == null) { | ||
return null; | ||
} | ||
headersBuilder.add(headerName, headerValue); | ||
headersBuilder.addUnsafeNonAscii(headerName, headerValue); |
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.
We have internal failures due to this line. The internal system is not able to find it.
I'm not an Android expert and I couldn't find from which version of OkHTTP this is available.
Could you help me out a bit here? 🙏
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.
It was added in 3.12.0: https://square.github.io/okhttp/changelogs/changelog_3x/#version-3120
RN is using v4 of okhttp now:
OKHTTP_VERSION=4.9.2 |
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.
Hi @cipolleschi hope you had a great week!
Is there any update on this?
All non-internal builds passed so I suppose the code should have built without problems.
Is the internal build using a different okhttp version than the one on GitHub? If you could attach logs (without sensitive info of course), it would be easier for me to help.
Also, I saw the Linter complained about a warning (not an error). Does this mean it is still mergeable?
Thank you.
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.
Jumping on this.
The build still fails internally. For your reference with this error:
ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java:754: error: cannot find symbol
[CONTEXT] headersBuilder.addUnsafeNonAscii(headerName, headerValue);
[CONTEXT] ^
[CONTEXT] symbol: method addUnsafeNonAscii(java.lang.String,java.lang.String)
[CONTEXT] location: variable headersBuilder of type okhttp3.Headers.Builder
Also, I saw the Linter complained about a warning (not an error). Does this mean it is still mergeable?
Currenty we can't merge this as it is, as our internal builds are red (not sure why they don't show up on Github though).
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.
Thank you @cortinico for looking into this!
So the method couldn't be found when compiled...
The code builds fine on CircleCI though. Is there any particularly special setup for internal builds?
For example, was the build that failed configured with a lower version of OkHttp?
Since I don't have access to the build logs and configurations, what's the best approach to the issue if the code builds fine in public but fails internally?
Thanks!
Edit: I synced with the main branch again to force rerun the jobs, hoping they all passes so it triggers the internal one again. I find the CI sometimes fails abruptly due to broken environments.
33711f2
to
b5749b6
Compare
PR build artifact for b5749b6 is ready. |
PR build artifact for 7ed0489 is ready. |
PR build artifact for 03fb462 is ready. |
Want to bump this PR. The fix passed all external checks but the internal ones, making it impossible for me to find the problem myself. This utf-8 fix, however, is important to developers in lots of non-English speaking countries and I wish it could be handled soon. Thank you! |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
dd10a95
to
0460aad
Compare
@cipolleschi would you mind importing the diff again? Want to see if there's any internal update that might have solved the linter issue. Thank you! |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Ok so I'm convinced some Meta internal apps are still using an old version of okhttp that is not caught up with the open source version (v4.9.2). To be honest, this feels so weird because it basically means we cannot use any newer features introduced in okhttp in open source React Native even if this repo has set its okhttp version to be v4. I've done what I can, but only people at Meta can fix this issue. |
Hi @robertying, sorry for the long silence. We were discussing this feature internally and, while we are looking to try and understand what needs to be done to make it work, we were exploring alternatives. Do you think would it be possible to make this feature an opt-in? 🤔 So, for example, if we switch a flag in the How do you feel about that? This would make much easier to land this as we will be preserving the base default behavior (and internal system won't break) but supporting the use case presented here. |
@cipolleschi I don't see any changes you requested. Did you mean to have dedicated functions to check? Also, I'm not sure how internal tests are still failing. 😅 I tested all these GitHub checks with a lower version of okhttp v3.11.0 and they all passed. |
ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java
Outdated
Show resolved
Hide resolved
My bad, I probably closed the page before submitting the suggestions... 🤦 |
@cipolleschi I see what you mean. In the meantime, can you check the linter error that was reported internally? |
@robertying, there are some internal tests failing, but these are snapshot tests because we changed the layout of HTTP, so they will be easy to fix for me as soon as we have a final version of the diff. If you can:
I can fix the tests and try to land it. Thank you so much for your patience. |
5cf6090
to
e869398
Compare
@cipolleschi woohoo! All tests passed. I used the static constructor to initialize the reflected method. Let me know if you think this is okay. |
/rebase |
Hello! Changes looks good to me, I'm not a Java expert really, but I think it make sense and it could work! |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
e869398
to
011075f
Compare
@cipolleschi Thanks! Also, usually the bot should have committed the code by now. Could you take a look when you have time? |
We are trying to understand if we can actually merge this. There could be performance implications in using reflection and the situation with OkHTTP is blocking other team internally, so we are trying to understand the best path forward. I'm sorry that this is taking so long to merge. :( |
No worries. Please keep me posted. |
@robertying sorry for the delay. |
@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @robertying in 7c7e9e6. When will my fix make it into a release? | Upcoming Releases |
@cortinico merged this pull request in 7c7e9e6. |
@robertying sorry for the delay, but we were finally able to ship this change. |
@cortinico no worries! Appreciate that you revisited this change and had it merged! Does this mean there's still an old okhttp version somewhere internal and we have to use reflections as a workaround? |
Nope we were able to update the internal usages to OkHTTP 3.12.x |
Ah I see! I just realized the commit imported was the original one without the reflection workaround, not the current changes listed in this PR. All good now. 👍 |
Summary
Fix #31537: [Android] React Native strips non-ASCII characters from HTTP headers
Changelog
[Android] [Changed] - Allow non-ascii header values on Android and add utf-8 filename fallback in FormData
Test Plan
react-native
repo.android:usesCleartextTraffic="true"
to AndroidManifest.xmladb reverse tcp:3000 tcp:3000
to connect the 3000 port on the emulator if necessary.RNTesterAppShared.js
to include test code: