react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[iOS] Websocket doesn't using system proxy settings

Open bill2004158 opened this issue 3 years ago • 5 comments

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.

bill2004158 avatar Jul 17 '20 11:07 bill2004158

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);

bill2004158 avatar Jul 18 '20 09:07 bill2004158

Any news on that?

hanayashiki avatar Feb 27 '21 01:02 hanayashiki

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

image

hanayashiki avatar Feb 27 '21 01:02 hanayashiki

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.

shaikhalid avatar Oct 11 '22 07:10 shaikhalid

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

hanayashiki avatar Oct 20 '22 04:10 hanayashiki