Skip to content

Commit 696456d

Browse files
authored
Merge pull request #12 from dkoster95/bugfix/HTTPResponse-Decoded
Added fix for Parameter mapping url and sendable types
2 parents 81e0e26 + 571870d commit 696456d

14 files changed

Lines changed: 29 additions & 24 deletions

File tree

Sources/Certificate Pinning/CertificatePinner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
public protocol CertificatePinner {
11+
public protocol CertificatePinner: Sendable {
1212
func isServerTrusted(challenge: URLAuthenticationChallenge) -> Bool
1313
}
1414

Sources/Certificate Pinning/CertificatePinningStrategy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import Foundation
1010

1111
public struct CertificatePinningStrategy: PinningStrategy {
12-
private let certificateBuilders: [() -> SecCertificate]
12+
private let certificateBuilders: [@Sendable () -> SecCertificate]
1313

14-
public init(certificateBuilders: [() -> SecCertificate]) {
14+
public init(certificateBuilders: [@Sendable () -> SecCertificate]) {
1515
self.certificateBuilders = certificateBuilders
1616
}
1717

Sources/Certificate Pinning/Hasher.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import Foundation
1010
import CryptoKit
1111

12-
public protocol Hasher {
12+
public protocol Hasher: Sendable {
1313
func hash(data: Data) -> String
1414
}
1515

16-
public class CKSHA256Hasher: Hasher {
16+
public final class CKSHA256Hasher: Hasher {
1717

1818
public init() {
1919

Sources/Certificate Pinning/PinningStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
import Foundation
1010

11-
public protocol PinningStrategy {
11+
public protocol PinningStrategy: Sendable {
1212
func validate(serverTrust: SecTrust) -> Bool
1313
}

Sources/Certificate Pinning/URLSessionPinningDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
public protocol URLSessionPinningDelegateAdaptable {
11+
public protocol URLSessionPinningDelegateAdaptable: Sendable {
1212
func urlSession(didReceive challenge: URLAuthenticationChallenge,
1313
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)
1414
}

Sources/ParameterEncoding/ParameterEncoding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
public enum HTTPMethod: String {
11+
public enum HTTPMethod: String, Sendable {
1212
case options = "OPTIONS"
1313
case get = "GET"
1414
case head = "HEAD"

Sources/ParameterEncoding/StringEncoding.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public class StringEncoding: ParameterEncoding {
5959
}
6060

6161
public struct StringURLTransformer: URLTransformer {
62+
63+
public init() {
64+
65+
}
66+
6267
public func transform(url: String, parameters: [String : any Sendable]) -> String {
6368
guard !parameters.isEmpty else { return url }
6469
var urlString = url

Sources/ParameterEncoding/URLTransformer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public struct ParameterMappingURLTransformer: URLTransformer {
3939
guard !url.isEmpty else { return url }
4040
let parameters = parameters.flatMap { (key, value) in EncodingHelpers.queryComponents(fromKey: key, value: value) }
4141
guard !parameters.isEmpty else { return url }
42-
var urlResult = EncodingHelpers.escape(url)
42+
var urlResult = url
4343
for (key, value) in parameters {
44-
let escapedKey = EncodingHelpers.escape("{\(key)}")
44+
let escapedKey = "{\(key)}"
4545
urlResult = urlResult.replacingOccurrences(of: escapedKey, with: value)
4646
}
4747
return urlResult

Sources/Request/HTTPRequest.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
import Foundation
88
import Combine
99

10-
public protocol DataTask: NSObjectProtocol {
10+
public protocol DataTask: NSObjectProtocol, Sendable {
1111
func resume()
1212
func suspend()
1313
func cancel()
1414
}
1515

16-
public protocol HTTPRequest {
16+
public protocol HTTPRequest: Sendable {
1717
var headers: [String: String] { get }
1818
var body: Data? { get }
1919
var url: String { get }
2020
var method: HTTPMethod { get }
2121
}
2222

23-
public protocol HTTPRequestActionable {
23+
public protocol HTTPRequestActionable: Sendable {
2424
func response() async throws -> HTTPResponse
2525
var responsePublisher: any Publisher<HTTPResponse, Error> { get }
2626
}
2727

28-
public protocol HTTPRequestDecodedActionable<ResponseType> {
28+
public protocol HTTPRequestDecodedActionable<ResponseType>: Sendable {
2929
associatedtype ResponseType: Codable
3030
func responseDecoded() async throws -> Response<ResponseType>
3131
var responseDecodedPublisher: any Publisher<ResponseType, Error> { get }

Sources/Request/HTTPResponse.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import Foundation
99

10-
public protocol HTTPResponse {
10+
public protocol HTTPResponse: Sendable {
1111
var statusCode: HTTPStatusCode { get }
12-
var headers: [AnyHashable: Any] { get }
12+
var headers: [String: String] { get }
1313
var body: Data? { get }
1414
}
1515

@@ -25,12 +25,12 @@ public extension HTTPResponse {
2525

2626
public struct QHHTTPResponse: HTTPResponse {
2727
public let statusCode: HTTPStatusCode
28-
public let headers: [AnyHashable : Any]
28+
public let headers: [String : String]
2929
public let body: Data?
3030

3131
public init(body: Data?, urlResponse: URLResponse) {
3232
self.body = body
33-
self.headers = (urlResponse as? HTTPURLResponse)?.allHeaderFields ?? [:]
33+
self.headers = ((urlResponse as? HTTPURLResponse)?.allHeaderFields as? [String: String]) ?? [:]
3434
self.statusCode = HTTPStatusCode(rawValue: (urlResponse as? HTTPURLResponse)?.statusCode ?? -1) ?? .serviceUnavailable
3535
}
3636
}

0 commit comments

Comments
 (0)