From 73a514136fc74b7ce793d859846c85ecad9b6274 Mon Sep 17 00:00:00 2001 From: Mihail Nacev Date: Tue, 31 Oct 2023 13:44:34 +0100 Subject: [PATCH] MOD request init for supporting additional headers --- Sources/GirdersSwift/http/Request.swift | 6 +++++- Tests/GirdersSwiftTests/swift/http/TestRequest.swift | 10 ++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/GirdersSwift/http/Request.swift b/Sources/GirdersSwift/http/Request.swift index 01db8f4..8d494a1 100644 --- a/Sources/GirdersSwift/http/Request.swift +++ b/Sources/GirdersSwift/http/Request.swift @@ -110,11 +110,15 @@ public struct Request: Equatable { self.sslCredentials = mutableRequest.sslCredentials } - public init(URL: URL, method: HTTPMethod = .GET, parameters: [String: AnyObject] = [:]) { + public init(URL: URL, + method: HTTPMethod = .GET, + parameters: [String: AnyObject] = [:], + additionalHeaders: [String: String] = [:]) { let requestGenerator = StandardRequestGenerator() self.init(URL: URL, method: method, parameters: parameters, + additionalHeaders: additionalHeaders, requestGenerator: requestGenerator) } diff --git a/Tests/GirdersSwiftTests/swift/http/TestRequest.swift b/Tests/GirdersSwiftTests/swift/http/TestRequest.swift index ca7354d..b5534a7 100644 --- a/Tests/GirdersSwiftTests/swift/http/TestRequest.swift +++ b/Tests/GirdersSwiftTests/swift/http/TestRequest.swift @@ -46,15 +46,14 @@ class TestRequest: XCTestCase { // Given let url = URL(string: "https://www.example.com/api")! let method: HTTPMethod = .GET - let parameters: [String : Any] = [:] + let parameters: [String : AnyObject] = [:] let additionalHeaders: [String: String] = ["User-Agent": "MyApp/1.0"] // When let request = Request(URL: url, method: method, parameters: parameters, - additionalHeaders: additionalHeaders, - requestGenerator: mockGenerator) + additionalHeaders: additionalHeaders) let sortedHeaderFields = request.headerFields.sorted { $0.key < $1.key } let sortedDictionary = Dictionary(uniqueKeysWithValues: sortedHeaderFields) @@ -66,13 +65,12 @@ class TestRequest: XCTestCase { // Given let url = URL(string: "https://www.example.com/api")! let method: HTTPMethod = .GET - let parameters: [String : Any] = [:] + let parameters: [String : AnyObject] = [:] // When let request = Request(URL: url, method: method, - parameters: parameters, - requestGenerator: mockGenerator) + parameters: parameters) let sortedHeaderFields = request.headerFields.sorted { $0.key < $1.key } let sortedDictionary = Dictionary(uniqueKeysWithValues: sortedHeaderFields)