Skip to content

Commit 59bc389

Browse files
cortinicometa-codesync[bot]
authored andcommitted
Apply custom headers in RCTReconnectingWebSocket (#55611)
Summary: Pull Request resolved: #55611 Inject custom devsupport headers into the HMR WebSocket connection. Changes from `initWithURL:` to `initWithURLRequest:` so headers can be set on the HTTP upgrade handshake. Changelog: [Internal] [Changed] - Reviewed By: cipolleschi Differential Revision: D93596718 fbshipit-source-id: ab028d0e03e11f0efde000d19943693439236dbc
1 parent dd02486 commit 59bc389

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#import <React/RCTConvert.h>
1111
#import <React/RCTDefines.h>
12+
#import <React/RCTDevSupportHttpHeaders.h>
1213

1314
#import <SocketRocket/SRWebSocket.h>
1415

@@ -46,7 +47,9 @@ - (void)start
4647
{
4748
[self stop];
4849
_stopped = NO;
49-
_socket = [[SRWebSocket alloc] initWithURL:_url];
50+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:_url];
51+
[[RCTDevSupportHttpHeaders sharedInstance] applyHeadersToRequest:request];
52+
_socket = [[SRWebSocket alloc] initWithURLRequest:request];
5053
_socket.delegate = self;
5154
[_socket setDelegateDispatchQueue:_delegateDispatchQueue];
5255
[_socket open];

0 commit comments

Comments
 (0)