react-native
react-native copied to clipboard
[iOS] Websocket doesn't using system proxy settings
Description
Fetch/Ajax can connect to our server with system proxy settings. however, websocket always connect fail.
React Native version:
0.62
Expected Results
websocket should connect servers like fetch/ajax using system proxy settings.
https://github.com/facebook/react-native/blob/master/Libraries/WebSocket/RCTSRWebSocket.m#L497 after created readStream,
then it should read system proxy settings:
CFDictionaryRef proxySettings = CFNetworkCopySystemProxySettings();
and apply to socket if has proxy:
CFReadStreamSetProperty((CFReadStreamRef)readStream, kCFStreamPropertySOCKSProxy, (CFTypeRef)proxyToUse);
Any news on that?
I don't know why everybody doesn't need such a proxy, for me the following code works:
I edited https://github.com/facebook/react-native/blob/master/Libraries/WebSocket/RCTSRWebSocket.m#L497 as below
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)host, port, &readStream, &writeStream);
CFDictionaryRef proxySettings = CFNetworkCopySystemProxySettings();
if (CFDictionaryContainsKey(proxySettings, kCFStreamPropertySOCKSProxyHost)) {
CFReadStreamSetProperty((CFReadStreamRef)readStream, kCFStreamPropertySOCKSProxy, (CFTypeRef)proxySettings);
CFReadStreamSetProperty((CFReadStreamRef)writeStream, kCFStreamPropertySOCKSProxy, (CFTypeRef)proxySettings);
}
_outputStream = CFBridgingRelease(writeStream);
_inputStream = CFBridgingRelease(readStream);
And it works like a charm. Little tips: For working with Charles proxy, you need to enable SOCKS Proxy which seems not enabled by default
Hi everyone, I am facing this exact problem. I am using expo, and hence I created an issue on expo but @Kudo mentioned that once react-native integrates this fix to their SDK it should come to expo.
Can someone please help me understand if there is any timelines for this.
Hi everyone, I am facing this exact problem. I am using expo, and hence I created an issue on expo but @Kudo mentioned that once react-native integrates this fix to their SDK it should come to expo.
Can someone please help me understand if there is any timelines for this.
no, there isn't. patch/fork your own version of react-native because facebook engineers don't have the time