mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Added Cookie Header to XML and Websocket request
Summary: Continuation of Pull Request #7167 https://github.com/facebook/react-native/pull/7167 Needed to clean my repository. So created this Pull Request Closes https://github.com/facebook/react-native/pull/10575 Differential Revision: D4955291 Pulled By: shergin fbshipit-source-id: 94b9a086b7cf70ee6cc152d0b1a36c260140450e
This commit is contained in:
committed by
Facebook Github Bot
parent
bea7659762
commit
047961fbf7
@@ -60,6 +60,20 @@ RCT_EXPORT_MODULE()
|
||||
RCT_EXPORT_METHOD(connect:(NSURL *)URL protocols:(NSArray *)protocols headers:(NSDictionary *)headers socketID:(nonnull NSNumber *)socketID)
|
||||
{
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
||||
|
||||
// We load cookies from sharedHTTPCookieStorage (shared with XHR and
|
||||
// fetch). To get secure cookies for wss URLs, replace wss with https
|
||||
// in the URL.
|
||||
NSURLComponents *components = [NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:true];
|
||||
if ([components.scheme.lowercaseString isEqualToString:@"wss"]) {
|
||||
components.scheme = @"https";
|
||||
}
|
||||
|
||||
// Load and set the cookie header.
|
||||
NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:components.URL];
|
||||
request.allHTTPHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
|
||||
|
||||
// Load supplied headers
|
||||
[headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
|
||||
[request addValue:[RCTConvert NSString:value] forHTTPHeaderField:key];
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user