-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Fetch only brings latest value of same-name headers on Android, works on iOS. #23005
Comments
Why this is importantYou cant use fetch with any server setting more than 1 cookie 🍪, in many S.O the resolution ended up being reverting to token based auth or custom headers The fact that it works on iOS is dangerous because one might develop their entire logic around cookie based auth only to find later that this isnt possible on Android having then to perform backend changes as well, maybe even the app is released originally on iOS even. |
on Android, RN concatenates values separated by comma(,), see react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java Line 606 in 4936d28
|
@dulmandakh The behaviour you're describing would have been fine but it is not the one I experienced. Only the latest value was present in my case. Please attempt to reproduce locally and you will see the same. I think the fact that it works with
means that it's a problem with the data structure used maybe? |
currently it uses ReadableNativeMap, where you must have unique keys. So they concatenate to workaround this limitation. Didn't see iOS code. |
works ok on iOS i will check again to make sure but i am fairly certain that concatenation isn't working and that only the latest value of the latest header is exposed |
@dulmandakh i've tested this again on a fresh install and i can definitely verify that it doesnt concatenate and only keeps the latest value without adding
on MainApplication.java without the addition: with the addition: I can be of assistance if you need to reproduce and I believe we should re-open this issue |
I can verify this is still an outstanding issue. The fact that i made it work for me shouldnt be reason to abandon this as others can have a really bad time with this in the future when already very deep in development with a server architecture in place that might be hard to change. Please consider re-opening. This is far from minor in my opinion. |
The truth @Return-1 ! I'm experiencing exactly the same, for me only the last This solution here #18837 (comment), is working for me, thanks Patrick. But it's highly annoying that this doesn't work :( ... + maybe uncertain side effects this workaround comes with. |
Hello, I had the same problem here and analysed the internal issue: The problem is a combination of react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java Lines 647 to 661 in 9895d01
That This flag defines if the ReadableNativeMap reads data from a native map or a internal (java.util.) HashMap. But the problem was that WritableNativeMap always writes into the native map and never uses the (Readable) internal HashMap. That was the reason why Like said by @hey99xx in #21795 (comment) and by @Return-1 #23005 (comment) its possible to activate the this native accessor, if you add this code to your own/project Add this imports: import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.bridge.ReadableNativeMap; And this add the beginning of the ReadableNativeArray.setUseNativeAccessor(true);
ReadableNativeMap.setUseNativeAccessor(true); For me this works fine. But notice that this global flag may cause some other troubles. I also started to fix this behaviour in the latest React Native 0.59.3 release, but notice than that the master version of ReadableNativeMap/WritableNativeMap was already changed. The commits b257e06 and a062b34 by FB eng @sahrens changed/removed the useNativeAccessor behaviour, so I hope this issue was also fixed with the next/upcoming minor release 0.60.0. 🙌 (I couldn't test the new version yet, because running from the npm package (also with sourcecode changes) works fine for me, but the sourcecode version of RN let fail some of my 3rd party libraries. I'm looking forward for a RC of 0.60.0 and maybe will update this text here then.) |
This is a long standing bug reported here #18837. Unfortunately #18837 became stale but i can confirm the problem persists.
Environment
React Native Environment Info:
Description
This is a long standing bug reported here #18837 and in different forms in many other places that i havent kept track of, will append later on with an edit.
The issue is that in the presence of multiple headers with the same name as is common with e.g
Set-Cookie
the android version of fetch will always only ever keep the latest cookie.So in practice if one wants to get more than one cookies at a time from the response they received they cant do it. There is a workaround which also described on #18837 and essentially introduces the following changes to
MainApplication.java
:However I am very uncertain as to what side-effects it might be causing elsewhere. Right now this is what im using but not feeling secure about it.
Reproducible Demo
Reproduction is identical to #18837 found here Reproduction can also be found in 18837 which i run and can confirm.
The text was updated successfully, but these errors were encountered: