Skip to content

Commit 131d757

Browse files
authored
Option to opt-out the Method Swizzling on WS/WSS Connection (#138)
* Able to opt-out the WS/WSS * Bump 1.23.0
1 parent 4579425 commit 131d757

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Sources/Atlantis.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,16 @@ public final class Atlantis: NSObject {
7777
/// Build version of Atlantis
7878
/// It's essential for Proxyman to known if it's compatible with this version
7979
/// Instead of receving the number from the info.plist, we should hardcode here because the info file doesn't exist in SPM
80-
public static let buildVersion: String = "1.22.0"
80+
public static let buildVersion: String = "1.23.0"
8181

8282
/// Start Swizzle all network functions and monitoring the traffic
8383
/// It also starts looking Bonjour network from Proxyman app.
8484
/// If hostName is nil, Atlantis will find all Proxyman apps in the network. It's useful if we have only one machine for personal usage.
8585
/// If hostName is not nil, Atlantis will try to connect to particular mac machine. It's useful if you have multiple Proxyman.
8686
/// - Parameter hostName: Host name of Mac machine. You can find your current Host Name in Proxyman -> Certificate -> Install on iOS -> By Atlantis -> Show Start Atlantis
87-
@objc public class func start(hostName: String? = nil) {
87+
/// - Parameter shouldCaptureWebSocketTraffic: Determine if Atlantis should perform the Method Swizzling on WS/WSS connection. Default is true.
88+
@objc public class func start(hostName: String? = nil, shouldCaptureWebSocketTraffic: Bool = true) {
89+
// save config
8890
let configuration = Configuration.default(hostName: hostName)
8991

9092
//
@@ -105,7 +107,7 @@ public final class Atlantis: NSObject {
105107

106108
// Enable the injector
107109
Atlantis.shared.configuration = configuration
108-
Atlantis.shared.injector.injectAllNetworkClasses()
110+
Atlantis.shared.injector.injectAllNetworkClasses(config: NetworkConfiguration(shouldCaptureWebSocketTraffic: shouldCaptureWebSocketTraffic))
109111

110112
// Start transport layer if need
111113
if Atlantis.shared.isEnabledTransportLayer {

Sources/NetworkInjector.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88

99
import Foundation
1010

11+
struct NetworkConfiguration {
12+
13+
/// Whether or not Atlantis should perform the Method Swizzling on WS/WSS connection.
14+
let shouldCaptureWebSocketTraffic: Bool
15+
16+
// init
17+
init(shouldCaptureWebSocketTraffic: Bool = true) {
18+
self.shouldCaptureWebSocketTraffic = shouldCaptureWebSocketTraffic
19+
}
20+
}
21+
1122
protocol Injector {
1223

1324
var delegate: InjectorDelegate? { get set }
14-
func injectAllNetworkClasses()
25+
func injectAllNetworkClasses(config: NetworkConfiguration)
1526
}
1627

1728
protocol InjectorDelegate: AnyObject {
@@ -38,17 +49,17 @@ final class NetworkInjector: Injector {
3849

3950
// MARK: - Internal
4051

41-
func injectAllNetworkClasses() {
52+
func injectAllNetworkClasses(config: NetworkConfiguration = NetworkConfiguration()) {
4253
// Make sure we swizzle *ONCE*
4354
DispatchQueue.once {
44-
injectAllURLSession()
55+
injectAllURLSession(config)
4556
}
4657
}
4758
}
4859

4960
extension NetworkInjector {
5061

51-
private func injectAllURLSession() {
62+
private func injectAllURLSession(_ config: NetworkConfiguration) {
5263

5364
// iOS 8: __NSCFURLSessionConnection
5465
// iOS 9, 10, 11, 12, 13, 14: __NSCFURLLocalSessionConnection
@@ -66,7 +77,10 @@ extension NetworkInjector {
6677
injectURLSessionUploadTasks()
6778

6879
// Websocket
69-
injectURLSessionWebsocketTasks()
80+
// Able to opt-out the WS/WSS if needed
81+
if config.shouldCaptureWebSocketTraffic {
82+
injectURLSessionWebsocketTasks()
83+
}
7084
}
7185

7286
private func injectIntoURLSessionDelegate(anyClass: AnyClass) {

atlantis-proxyman.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "atlantis-proxyman"
3-
spec.version = "1.22.0"
3+
spec.version = "1.23.0"
44
spec.summary = "A lightweight and powerful iOS framework for intercepting HTTP/HTTPS Traffic"
55
spec.description = <<-DESC
66
A lightweight and powerful iOS framework for intercepting HTTP/HTTPS Traffic from your app. No more messing around with proxy, certificate config.

0 commit comments

Comments
 (0)