Skip to content

Commit

Permalink
MOD request init for supporting additional headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Nacev authored and mihailnacev committed Oct 31, 2023
1 parent 3e2bc79 commit 73a5141
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Sources/GirdersSwift/http/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 4 additions & 6 deletions Tests/GirdersSwiftTests/swift/http/TestRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit 73a5141

Please sign in to comment.