Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: Fix missing requests when ignore urlprotocol #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions Sources/Atlantis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ extension Atlantis {
#endif
}

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

// Get the canInitWithRequest: selector
let selector = NSSelectorFromString("canInitWithRequest:")
Expand Down Expand Up @@ -259,8 +259,16 @@ extension Atlantis {
return nil
}

// Just check ignore protocols if it's not empty and the session resumes the task has this protocol
var sessionProtocols: [AnyClass] = []
if !ignoreProtocols.isEmpty, let session = task.value(forKey: "session") as? URLSession {
let protocols = Set((session.configuration.protocolClasses ?? []).map { NSStringFromClass($0) })
let shouldIgnores = Set(ignoreProtocols.map { NSStringFromClass($0) })
sessionProtocols = protocols.intersection(shouldIgnores).compactMap { NSClassFromString($0) }
}

// check should ignore this request because it's duplicated by URLProtocol classes
if checkShouldIgnoreByURLProtocol(on: request) {
if checkShouldIgnoreByURLProtocol(protocols: sessionProtocols, on: request) {
ignoredRequestIds.insert(id)
return nil
}
Expand Down