Skip to content

Commit

Permalink
I was unable to see any websocket traffic in Charles proxy. In order …
Browse files Browse the repository at this point in the history
…to enable websocket inspection I applied the snippet by https://github.com/kevinmlong that is mentioned here: #240
  • Loading branch information
neoneye committed Nov 15, 2017
1 parent 8f2af31 commit b074c6c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ open class FoundationStream : NSObject, WSStream, StreamDelegate {
private var outputStream: OutputStream?
public weak var delegate: WSStreamDelegate?
let BUFFER_MAX = 4096

public var enableSOCKSProxy = false

public func connect(url: URL, port: Int, timeout: TimeInterval, ssl: SSLSettings, completion: @escaping ((Error?) -> Void)) {
var readStream: Unmanaged<CFReadStream>?
Expand All @@ -140,6 +142,15 @@ open class FoundationStream : NSObject, WSStream, StreamDelegate {
CFStreamCreatePairWithSocketToHost(nil, h, UInt32(port), &readStream, &writeStream)
inputStream = readStream!.takeRetainedValue()
outputStream = writeStream!.takeRetainedValue()

if enableSOCKSProxy {
let proxyDict = CFNetworkCopySystemProxySettings()
let socksConfig = CFDictionaryCreateMutableCopy(nil, 0, proxyDict!.takeRetainedValue())
let propertyKey = CFStreamPropertyKey(rawValue: kCFStreamPropertySOCKSProxy)
CFWriteStreamSetProperty(outputStream, propertyKey, socksConfig)
CFReadStreamSetProperty(inputStream, propertyKey, socksConfig)
}

guard let inStream = inputStream, let outStream = outputStream else { return }
inStream.delegate = self
outStream.delegate = self
Expand Down

0 comments on commit b074c6c

Please sign in to comment.