 import Foundation
 
 public class Sniffer: URLProtocol {
-    
+
     private enum Keys {
         static let request = "Sniffer.request"
         static let duration = "Sniffer.duration"
     }
-    
+
     static public var onLogger: ((String) -> Void)? // If the handler is registered, the log inside the Sniffer will not be output.
-    
+
     private lazy var session: URLSession = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil)
     private var urlTask: URLSessionDataTask?
     private var urlRequest: NSMutableURLRequest?
     private var urlResponse: HTTPURLResponse?
     private var data: Data?
     private let serialQueue = DispatchQueue(label: "com.kofktu.sniffer.serialQueue")
-    
+
     private static var bodyDeserializers: [String: BodyDeserializer] = [
         "application/x-www-form-urlencoded": PlainTextBodyDeserializer(),
         "*/json": JSONBodyDeserializer(),

            self?.session.invalidateAndCancel()
        }
    }
    
    // MARK: - Private
    private func log(_ string: String) {
        if let _ = Sniffer.onLogger {
            Sniffer.onLogger?(string)

            return data as Data
        }
    }

    private func find(deserialize contentType: String) -> BodyDeserializer? {
        for (pattern, deserializer) in Sniffer.bodyDeserializers {
            do {
                let regex = try NSRegularExpression(pattern: pattern.replacingOccurrences(of: "*", with: "[a-z]+"))
                let results = regex.matches(in: contentType, range: NSRange(location: 0, length: contentType.count))

                if !results.isEmpty {
                    return deserializer
                }
