Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Show socket transactions in iOS simulator with proxy #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ let ws = WebSocket("ws://url")
ws.allowSelfSignedSSL = true
```

## Show Socket Transaction in iOS Simulator with Proxy

```swift
let ws = WebSocket("ws://url")
ws.allowProxyInSimulator = true
```

## Network Services (VoIP, Video, Background, Voice)

```swift
Expand Down
17 changes: 17 additions & 0 deletions Source/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ private class InnerWebSocket: Hashable {
var _subProtocol = ""
var _compression = WebSocketCompression()
var _allowSelfSignedSSL = false
var _allowProxyInSimulator = false
var _services = WebSocketService.None
var _event = WebSocketEvents()
var _eventDelegate: WebSocketDelegate?
Expand All @@ -560,6 +561,10 @@ private class InnerWebSocket: Hashable {
get { lock(); defer { unlock() }; return _allowSelfSignedSSL }
set { lock(); defer { unlock() }; _allowSelfSignedSSL = newValue }
}
var allowProxyInSimulator : Bool {
get { lock(); defer { unlock() }; return _allowProxyInSimulator }
set { lock(); defer { unlock() }; _allowProxyInSimulator = newValue }
}
var services : WebSocketService {
get { lock(); defer { unlock() }; return _services }
set { lock(); defer { unlock() }; _services = newValue }
Expand Down Expand Up @@ -593,6 +598,7 @@ private class InnerWebSocket: Hashable {
ws.eclose = eclose
ws.compression = compression
ws.allowSelfSignedSSL = allowSelfSignedSSL
ws.allowProxyInSimulator = allowProxyInSimulator
ws.services = services
ws.event = event
ws.eventQueue = eventQueue
Expand Down Expand Up @@ -1085,6 +1091,12 @@ private class InnerWebSocket: Hashable {
rd.setProperty(prop, forKey: Stream.PropertyKey(rawValue: kCFStreamPropertySSLSettings as String as String))
wr.setProperty(prop, forKey: Stream.PropertyKey(rawValue: kCFStreamPropertySSLSettings as String as String))
}
if allowProxyInSimulator {
let proxyDict = CFNetworkCopySystemProxySettings()
let prop = CFDictionaryCreateMutableCopy(nil, 0, proxyDict!.takeRetainedValue())
rd.setProperty(prop, forKey: Stream.PropertyKey(rawValue: kCFStreamPropertySOCKSProxy as String as String))
wr.setProperty(prop, forKey: Stream.PropertyKey(rawValue: kCFStreamPropertySOCKSProxy as String as String))
}
rd.delegate = delegate
wr.delegate = delegate
rd.schedule(in: RunLoop.main, forMode: RunLoopMode.defaultRunLoopMode)
Expand Down Expand Up @@ -1702,6 +1714,11 @@ open class WebSocket: NSObject {
get { return ws.allowSelfSignedSSL }
set { ws.allowSelfSignedSSL = newValue }
}
/// Allow to use Proxy to capture the websocket transfer. Default is false.
open var allowProxyInSimulator : Bool{
get { return ws.allowProxyInSimulator }
set { ws.allowProxyInSimulator = newValue }
}
/// The services of the WebSocket.
open var services : WebSocketService{
get { return ws.services }
Expand Down