Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Libraries/WebSocket/RCTSRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,23 @@ - (instancetype)initWithURL:(NSURL *)URL protocols:(NSArray<NSString *> *)protoc

- (instancetype)initWithURL:(NSURL *)URL protocols:(NSArray<NSString *> *)protocols options:(NSDictionary<NSString *, id> *)options
{
NSURLRequest *request = URL ? [NSURLRequest requestWithURL:URL] : nil;
NSMutableURLRequest *request;
if (URL) {
// Build a mutable request so we can fill the cookie header.
request = [NSMutableURLRequest requestWithURL:URL];

// We load cookies from sharedHTTPCookieStorage (shared with XHR and
// fetch). To get HTTPS-only cookies for wss URLs, replace wss with https
// in the URL.
NSURLComponents *components = [NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:true];
if ([components.scheme isEqualToString:@"wss"]) {
components.scheme = @"https";
}

// Load and set the cookie header.
NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:components.URL];
[request setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:cookies]];
}
return [self initWithURLRequest:request protocols:protocols options:options];
}

Expand Down