Skip to content

Commit

Permalink
Important fix for HttpRequest not always using the provided encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasMata committed Apr 18, 2024
1 parent 169bb2d commit c1808f6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ApiKit/Sources/HttpRequest.swift
Expand Up @@ -122,35 +122,35 @@ public extension HttpRequest {
convenience init<T: Encodable>(url: String, method: HttpMethod,
headers: [String: String] = [:],
body: T? = nil,
encoder _: DataEncoder = JSONEncoder(),
contentType _: String = "application/json") throws
encoder: DataEncoder = JSONEncoder(),
contentType: String = "application/json") throws
{
guard let url = URL(string: url) else {
fatalError("Invalid URL")
}
try self.init(url: url, method: method, headers: headers, body: body)
try self.init(url: url, method: method, headers: headers, body: body, encoder: encoder, contentType: contentType)
}

convenience init<T: Encodable>(host: String,
path: String,
method: HttpMethod,
headers: [String: String] = [:],
body: T? = nil,
encoder _: DataEncoder = JSONEncoder(),
contentType _: String = "application/json") throws
encoder: DataEncoder = JSONEncoder(),
contentType: String = "application/json") throws
{
try self.init(url: "\(host)\(path)", method: method, headers: headers, body: body)
try self.init(url: "\(host)\(path)", method: method, headers: headers, body: body, encoder: encoder, contentType: contentType)
}

convenience init<T: Encodable>(endpoint: EndpointInfo,
path: String,
method: HttpMethod,
headers: [String: String] = [:],
body: T? = nil,
encoder _: DataEncoder = JSONEncoder(),
contentType _: String = "application/json") throws
encoder: DataEncoder = JSONEncoder(),
contentType: String = "application/json") throws
{
try self.init(host: endpoint.url, path: path, method: method, headers: HttpRequest.combining(headers, endpoint.headers), body: body)
try self.init(host: endpoint.url, path: path, method: method, headers: HttpRequest.combining(headers, endpoint.headers), body: body, encoder: encoder, contentType: contentType)
}

static func post(endpoint: EndpointInfo, path: String, rawBody: Data? = nil, headers: [String: String] = [:]) -> HttpRequest {
Expand Down

0 comments on commit c1808f6

Please sign in to comment.