Skip to content

Commit 63d919e

Browse files
Updating native WebSocket header logic to match RN (#13366)
* Updating native WebSocket header logic to match RN * Change files * Fixing linting error --------- Co-authored-by: Sam Walker <[email protected]>
1 parent 44090cb commit 63d919e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Updating native WebSocket header logic to match RN",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Shared/Modules/WebSocketModule.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,8 @@ void WebSocketTurboModule::Connect(
416416
auto &optHeaders = options.headers;
417417
if (optHeaders.has_value()) {
418418
auto &headersVal = optHeaders.value();
419-
for (const auto &headerVal : headersVal.AsArray()) {
419+
for (const auto &entry : headersVal.AsObject()) {
420420
// Each header JSValueObject should only contain one key-value pair
421-
const auto &entry = *headerVal.AsObject().cbegin();
422421
rcOptions.emplace(winrt::to_hstring(entry.first), entry.second.AsString());
423422
}
424423
}

vnext/Shared/Networking/WinRTWebSocketResource.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ void WinRTWebSocketResource::Connect(string &&url, const Protocols &protocols, c
382382
scheme = L"https";
383383
}
384384

385-
auto origin = winrt::hstring{scheme + L"://" + host + L":" + winrt::to_hstring(port)};
385+
// Only add a port if a port is defined
386+
winrt::hstring originPort = port != 0 ? L":" + winrt::to_hstring(port) : L"";
387+
auto origin = winrt::hstring{scheme + L"://" + host + originPort};
388+
386389
m_socket.SetRequestHeader(L"Origin", std::move(origin));
387390
}
388391

0 commit comments

Comments
 (0)