Skip to content

Commit 4644c42

Browse files
authored
hotfix: Fix missing requests when ignore urlprotocol (#157)
1 parent ec7ecc8 commit 4644c42

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Sources/Atlantis.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ extension Atlantis {
207207
#endif
208208
}
209209

210-
private func checkShouldIgnoreByURLProtocol(on request: URLRequest) -> Bool {
210+
private func checkShouldIgnoreByURLProtocol(protocols: [AnyClass], on request: URLRequest) -> Bool {
211211
// Get the BBHTTPProtocolHandler class by name
212-
for cls in ignoreProtocols {
212+
for cls in protocols {
213213

214214
// Get the canInitWithRequest: selector
215215
let selector = NSSelectorFromString("canInitWithRequest:")
@@ -259,8 +259,16 @@ extension Atlantis {
259259
return nil
260260
}
261261

262+
// Just check ignore protocols if it's not empty and the session resumes the task has this protocol
263+
var sessionProtocols: [AnyClass] = []
264+
if !ignoreProtocols.isEmpty, let session = task.value(forKey: "session") as? URLSession {
265+
let protocols = Set((session.configuration.protocolClasses ?? []).map { NSStringFromClass($0) })
266+
let shouldIgnores = Set(ignoreProtocols.map { NSStringFromClass($0) })
267+
sessionProtocols = protocols.intersection(shouldIgnores).compactMap { NSClassFromString($0) }
268+
}
269+
262270
// check should ignore this request because it's duplicated by URLProtocol classes
263-
if checkShouldIgnoreByURLProtocol(on: request) {
271+
if checkShouldIgnoreByURLProtocol(protocols: sessionProtocols, on: request) {
264272
ignoredRequestIds.insert(id)
265273
return nil
266274
}

0 commit comments

Comments
 (0)