-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Updating native WebSocket header logic to match RN #13366
Updating native WebSocket header logic to match RN #13366
Conversation
e2807d0
to
22a9c62
Compare
112231c
to
0ce4401
Compare
Thanks for your submission. Regarding issue number 1, |
@@ -382,7 +382,10 @@ void WinRTWebSocketResource::Connect(string &&url, const Protocols &protocols, c | |||
scheme = L"https"; | |||
} | |||
|
|||
auto origin = winrt::hstring{scheme + L"://" + host + L":" + winrt::to_hstring(port)}; | |||
// Only add a port if a port is defined | |||
winrt::hstring originPort = port != 0 ? L":" + winrt::to_hstring(port) : L""; |
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.
For follow-up:
While this change prevents from appending a port with value 0
when the intended value may have been the protocol defaults (80
, 443
), this would prevent a client app from explicitly using such port, even though it's against conventions and possibly standards.
We should use the same URL processing as OriginPolicyHttpFilter.cpp to prevent a few corner cases such as explicitly set default ports.
See #12626 and OfficeDev/office-js#4144.
Description
Type of Change
Why
There are two bugs at play. This fixes both bugs, allowing headers to be properly used with web socket requests.
Bug #1
In
Libraries/WebSocket/WebSocket.js
, the expected type forheaders
is an object. This is passed down as-is to the native layer in the callNativeWebSocketModule.connect(url, protocols, {headers}, this._socketId);
. The turbo module implementation attempts to iterative over this box type by using.AsArray()
, which immediately continues past the for-loop. The result is that any headers passed down from Javascript are ignored.Bug #2
React Native WebSocket implementations do not put a port on the Origin header when a port is not provided. RNW does, which results in adding a port of 0 to every default Origin header. Port 0 is reserved and is not meant to be used.
The combination of both of these bugs means every web socket request will only have one header and it will be a improperly constructed Origin header.
Resolves [Add Relevant Issue Here]
While I don't know which version of RNW this was introduced in, when Xbox updated an app from RNW 0.69 to 0.73, all web socket requests broke due to services rejecting origin headers wiht port 0. This works fine on mobile apps due.
What
WebSocketModule.cpp
: Changed the usage of.AsArray()
to.AsObject()
to match expectations of headers type that is passed down by JavascriptWinRTWebSocketResource.cpp
: Changed default origin header construction to only add a port if it is not 0.Testing
Xbox is currently using a patch that applies both of these changes.
Changelog
yes?
WebSocket headers are now properly applied when using Turbo Modules
Microsoft Reviewers: Open in CodeFlow