@onekeyfe/react-native-sni-connect 3.0.81-alpha.2 → 3.0.81-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -90,15 +90,22 @@ final class SniConnectPinnedResolverLease {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
final class SniConnectSessionInvalidationDelegate: NSObject,
|
|
93
|
+
final class SniConnectSessionInvalidationDelegate: NSObject, URLSessionDataDelegate {
|
|
94
94
|
private let hostname: String
|
|
95
95
|
private let ip: String
|
|
96
96
|
private let resolverLease: SniConnectPinnedResolverLease
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
private weak var forwardingDataDelegate: URLSessionDataDelegate?
|
|
98
|
+
|
|
99
|
+
init(
|
|
100
|
+
hostname: String,
|
|
101
|
+
ip: String,
|
|
102
|
+
resolverLease: SniConnectPinnedResolverLease,
|
|
103
|
+
forwardingDataDelegate: URLSessionDataDelegate? = nil
|
|
104
|
+
) {
|
|
99
105
|
self.hostname = hostname
|
|
100
106
|
self.ip = ip
|
|
101
107
|
self.resolverLease = resolverLease
|
|
108
|
+
self.forwardingDataDelegate = forwardingDataDelegate
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
func urlSession(_ session: URLSession, didBecomeInvalidWithError error: Error?) {
|
|
@@ -110,6 +117,64 @@ final class SniConnectSessionInvalidationDelegate: NSObject, URLSessionDelegate
|
|
|
110
117
|
("success", error == nil),
|
|
111
118
|
]))
|
|
112
119
|
}
|
|
120
|
+
|
|
121
|
+
func urlSession(
|
|
122
|
+
_ session: URLSession,
|
|
123
|
+
task: URLSessionTask,
|
|
124
|
+
willPerformHTTPRedirection response: HTTPURLResponse,
|
|
125
|
+
newRequest request: URLRequest,
|
|
126
|
+
completionHandler: @escaping (URLRequest?) -> Void
|
|
127
|
+
) {
|
|
128
|
+
if let forwardingDataDelegate {
|
|
129
|
+
forwardingDataDelegate.urlSession?(
|
|
130
|
+
session,
|
|
131
|
+
task: task,
|
|
132
|
+
willPerformHTTPRedirection: response,
|
|
133
|
+
newRequest: request,
|
|
134
|
+
completionHandler: completionHandler
|
|
135
|
+
)
|
|
136
|
+
} else {
|
|
137
|
+
completionHandler(nil)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
func urlSession(
|
|
142
|
+
_ session: URLSession,
|
|
143
|
+
dataTask: URLSessionDataTask,
|
|
144
|
+
didReceive response: URLResponse,
|
|
145
|
+
completionHandler: @escaping (URLSession.ResponseDisposition) -> Void
|
|
146
|
+
) {
|
|
147
|
+
forwardingDataDelegate?.urlSession?(
|
|
148
|
+
session,
|
|
149
|
+
dataTask: dataTask,
|
|
150
|
+
didReceive: response,
|
|
151
|
+
completionHandler: completionHandler
|
|
152
|
+
) ?? completionHandler(.cancel)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
func urlSession(
|
|
156
|
+
_ session: URLSession,
|
|
157
|
+
dataTask: URLSessionDataTask,
|
|
158
|
+
didReceive data: Data
|
|
159
|
+
) {
|
|
160
|
+
forwardingDataDelegate?.urlSession?(
|
|
161
|
+
session,
|
|
162
|
+
dataTask: dataTask,
|
|
163
|
+
didReceive: data
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
func urlSession(
|
|
168
|
+
_ session: URLSession,
|
|
169
|
+
task: URLSessionTask,
|
|
170
|
+
didCompleteWithError error: Error?
|
|
171
|
+
) {
|
|
172
|
+
forwardingDataDelegate?.urlSession?(
|
|
173
|
+
session,
|
|
174
|
+
task: task,
|
|
175
|
+
didCompleteWithError: error
|
|
176
|
+
)
|
|
177
|
+
}
|
|
113
178
|
}
|
|
114
179
|
|
|
115
180
|
/// Core HTTPS client that enforces IP direct connection with SNI.
|
|
@@ -30,7 +30,8 @@ public final class SniConnectPinnedSession {
|
|
|
30
30
|
public enum SniConnectPinnedTransport {
|
|
31
31
|
static func makeResources(
|
|
32
32
|
hostname: String,
|
|
33
|
-
ip: String
|
|
33
|
+
ip: String,
|
|
34
|
+
dataDelegate: URLSessionDataDelegate? = nil
|
|
34
35
|
) throws -> SniConnectPinnedTransportResources {
|
|
35
36
|
try SniConnectValidation.validateHostname(hostname)
|
|
36
37
|
try SniConnectValidation.validatePublicIP(ip)
|
|
@@ -65,7 +66,8 @@ public enum SniConnectPinnedTransport {
|
|
|
65
66
|
let delegate = SniConnectSessionInvalidationDelegate(
|
|
66
67
|
hostname: normalizedHostname,
|
|
67
68
|
ip: ip,
|
|
68
|
-
resolverLease: resolverLease
|
|
69
|
+
resolverLease: resolverLease,
|
|
70
|
+
forwardingDataDelegate: dataDelegate
|
|
69
71
|
)
|
|
70
72
|
return SniConnectPinnedTransportResources(
|
|
71
73
|
configuration: configuration,
|
|
@@ -76,10 +78,15 @@ public enum SniConnectPinnedTransport {
|
|
|
76
78
|
|
|
77
79
|
public static func makeSession(
|
|
78
80
|
hostname: String,
|
|
79
|
-
ip: String
|
|
81
|
+
ip: String,
|
|
82
|
+
dataDelegate: URLSessionDataDelegate? = nil
|
|
80
83
|
) throws -> SniConnectPinnedSession {
|
|
81
84
|
SniConnectPinnedSession(
|
|
82
|
-
resources: try makeResources(
|
|
85
|
+
resources: try makeResources(
|
|
86
|
+
hostname: hostname,
|
|
87
|
+
ip: ip,
|
|
88
|
+
dataDelegate: dataDelegate
|
|
89
|
+
)
|
|
83
90
|
)
|
|
84
91
|
}
|
|
85
92
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-sni-connect",
|
|
3
|
-
"version": "3.0.81-alpha.
|
|
3
|
+
"version": "3.0.81-alpha.4",
|
|
4
4
|
"description": "A React Native library for SNI-based HTTP requests with DNS caching and request management",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|