From c1808f6554ba2c71895bf0f09e6e92e3e2258c26 Mon Sep 17 00:00:00 2001 From: Nicholas Mata Date: Thu, 18 Apr 2024 16:39:52 -0700 Subject: [PATCH] Important fix for HttpRequest not always using the provided encoder. --- ApiKit/Sources/HttpRequest.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ApiKit/Sources/HttpRequest.swift b/ApiKit/Sources/HttpRequest.swift index 3e0362b..e8cacf2 100644 --- a/ApiKit/Sources/HttpRequest.swift +++ b/ApiKit/Sources/HttpRequest.swift @@ -122,13 +122,13 @@ public extension HttpRequest { convenience init(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(host: String, @@ -136,10 +136,10 @@ public extension HttpRequest { 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(endpoint: EndpointInfo, @@ -147,10 +147,10 @@ public extension HttpRequest { 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 {