Skip to content

Commit 9a1ecc0

Browse files
Merge pull request #1108 from apollographql/add/websocket-property
Add ability to get to Starscream's underlying SOCKS proxy property.
2 parents 2e0d56e + 00c4725 commit 9a1ecc0

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

Sources/ApolloWebSocket/ApolloWebSocket.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,34 @@ public protocol ApolloWebSocketClient: WebSocketClient {
1919
var callbackQueue: DispatchQueue { get set }
2020
}
2121

22+
public protocol SOCKSProxyable {
23+
24+
/// Determines whether a SOCKS proxy is enabled on the underlying request.
25+
/// Mostly useful for debugging with tools like Charles Proxy.
26+
var enableSOCKSProxy: Bool { get set }
27+
}
28+
2229
// MARK: - WebSocket
2330

2431
/// Included implementation of an `ApolloWebSocketClient`, based on `Starscream`'s `WebSocket`.
25-
public class ApolloWebSocket: WebSocket, ApolloWebSocketClient {
32+
public class ApolloWebSocket: WebSocket, ApolloWebSocketClient, SOCKSProxyable {
33+
34+
private var stream: FoundationStream!
35+
36+
public var enableSOCKSProxy: Bool {
37+
get {
38+
return self.stream.enableSOCKSProxy
39+
}
40+
set {
41+
self.stream.enableSOCKSProxy = newValue
42+
}
43+
}
44+
2645
required public convenience init(request: URLRequest, protocols: [String]? = nil) {
46+
let stream = FoundationStream()
2747
self.init(request: request,
2848
protocols: protocols,
29-
stream: FoundationStream())
49+
stream: stream)
50+
self.stream = stream
3051
}
3152
}

Sources/ApolloWebSocket/WebSocketTransport.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@ public class WebSocketTransport {
6161
self.addApolloClientHeaders(to: &self.websocket.request)
6262
}
6363
}
64+
65+
/// Determines whether a SOCKS proxy is enabled on the underlying request.
66+
/// Mostly useful for debugging with tools like Charles Proxy.
67+
/// Note: Will return `false` from the getter and no-op the setter for implementations that do not conform to `SOCKSProxyable`.
68+
public var enableSOCKSProxy: Bool {
69+
get {
70+
guard let socket = self.websocket as? SOCKSProxyable else {
71+
// If it's not proxyable, then the proxy can't be enabled
72+
return false
73+
}
74+
75+
return socket.enableSOCKSProxy
76+
}
77+
set {
78+
guard var socket = self.websocket as? SOCKSProxyable else {
79+
// If it's not proxyable, there's nothing to do here.
80+
return
81+
}
82+
83+
socket.enableSOCKSProxy = newValue
84+
}
85+
}
6486

6587
/// Designated initializer
6688
///

0 commit comments

Comments
 (0)