Skip to content

Commit

Permalink
Updating native WebSocket header logic to match RN (#13366)
Browse files Browse the repository at this point in the history
* Updating native WebSocket header logic to match RN

* Change files

* Fixing linting error

---------

Co-authored-by: Sam Walker <[email protected]>
  • Loading branch information
slswalker and sawalkerXbox authored Jul 16, 2024
1 parent 44090cb commit 63d919e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Updating native WebSocket header logic to match RN",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 1 addition & 2 deletions vnext/Shared/Modules/WebSocketModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,8 @@ void WebSocketTurboModule::Connect(
auto &optHeaders = options.headers;
if (optHeaders.has_value()) {
auto &headersVal = optHeaders.value();
for (const auto &headerVal : headersVal.AsArray()) {
for (const auto &entry : headersVal.AsObject()) {
// Each header JSValueObject should only contain one key-value pair
const auto &entry = *headerVal.AsObject().cbegin();
rcOptions.emplace(winrt::to_hstring(entry.first), entry.second.AsString());
}
}
Expand Down
5 changes: 4 additions & 1 deletion vnext/Shared/Networking/WinRTWebSocketResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"";
auto origin = winrt::hstring{scheme + L"://" + host + originPort};

m_socket.SetRequestHeader(L"Origin", std::move(origin));
}

Expand Down

0 comments on commit 63d919e

Please sign in to comment.