mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
- Origin header check shouldn't be case sensitive (#27827)
Summary: Based on [this](https://stackoverflow.com/a/5259004), header names are not case sensitive. That means that it's valid to pass a header `Origin` or `origin`. With the current implementation. on Android only, if you pass `Origin`, it will get overwritten by the default origin. This made me waste a lot of time debugging a problem while trying to connect to a websockets server that required an `origin` header and my implementation was working fine in iOS but not on Android, so I'm suggest changing the logic a little bit to take that into account. ## Changelog [Android] [Fixed] - Support for case insensitive "Origin" headers for Websockets Pull Request resolved: https://github.com/facebook/react-native/pull/27827 Test Plan: Here's a screenshot of that shows the issue before the fix (`Origin` header set, but getting overridden)  The fix is not that easy to test since it requires a public websocket server that checks for a custom Origin header, but I think the code changes are very small and clear. Differential Revision: D19578860 Pulled By: cpojer fbshipit-source-id: d854e887d1b9e8e54da662b2da2ebe08ce65fdbc
This commit is contained in:
committed by
Facebook Github Bot
parent
7a13a1a88f
commit
aeaf286c77
+8
-5
@@ -102,6 +102,8 @@ public final class WebSocketModule extends NativeWebSocketModuleSpec {
|
||||
builder.addHeader("Cookie", cookie);
|
||||
}
|
||||
|
||||
boolean hasOriginHeader = false;
|
||||
|
||||
if (options != null
|
||||
&& options.hasKey("headers")
|
||||
&& options.getType("headers").equals(ReadableType.Map)) {
|
||||
@@ -109,19 +111,20 @@ public final class WebSocketModule extends NativeWebSocketModuleSpec {
|
||||
ReadableMap headers = options.getMap("headers");
|
||||
ReadableMapKeySetIterator iterator = headers.keySetIterator();
|
||||
|
||||
if (!headers.hasKey("origin")) {
|
||||
builder.addHeader("origin", getDefaultOrigin(url));
|
||||
}
|
||||
|
||||
while (iterator.hasNextKey()) {
|
||||
String key = iterator.nextKey();
|
||||
if (ReadableType.String.equals(headers.getType(key))) {
|
||||
if (key.equalsIgnoreCase("origin")) {
|
||||
hasOriginHeader = true;
|
||||
}
|
||||
builder.addHeader(key, headers.getString(key));
|
||||
} else {
|
||||
FLog.w(ReactConstants.TAG, "Ignoring: requested " + key + ", value not a string");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if (!hasOriginHeader) {
|
||||
builder.addHeader("origin", getDefaultOrigin(url));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user