From 272715df854d1322fd86470ae2af99ecfa7f989a Mon Sep 17 00:00:00 2001 From: James Im <28934835+iamjamesim@users.noreply.github.com> Date: Wed, 15 Nov 2023 00:16:45 -0800 Subject: [PATCH 1/2] fix: do not override Content-Type header (#6) Co-authored-by: James Im <28934835+imjamesim@users.noreply.github.com> --- Sources/Functions/Types.swift | 10 +++++----- Tests/FunctionsTests/FunctionInvokeOptionsTests.swift | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/Functions/Types.swift b/Sources/Functions/Types.swift index 6770a87..7a946fc 100644 --- a/Sources/Functions/Types.swift +++ b/Sources/Functions/Types.swift @@ -18,23 +18,23 @@ public struct FunctionInvokeOptions { let body: Data? public init(method: Method? = nil, headers: [String: String] = [:], body: some Encodable) { - var headers = headers + var defaultHeaders = [String: String]() switch body { case let string as String: - headers["Content-Type"] = "text/plain" + defaultHeaders["Content-Type"] = "text/plain" self.body = string.data(using: .utf8) case let data as Data: - headers["Content-Type"] = "application/octet-stream" + defaultHeaders["Content-Type"] = "application/octet-stream" self.body = data default: // default, assume this is JSON - headers["Content-Type"] = "application/json" + defaultHeaders["Content-Type"] = "application/json" self.body = try? JSONEncoder().encode(body) } self.method = method - self.headers = headers + self.headers = defaultHeaders.merging(headers) { _, new in new } } public init(method: Method? = nil, headers: [String: String] = [:]) { diff --git a/Tests/FunctionsTests/FunctionInvokeOptionsTests.swift b/Tests/FunctionsTests/FunctionInvokeOptionsTests.swift index ef5ae21..329e97e 100644 --- a/Tests/FunctionsTests/FunctionInvokeOptionsTests.swift +++ b/Tests/FunctionsTests/FunctionInvokeOptionsTests.swift @@ -23,4 +23,15 @@ final class FunctionInvokeOptionsTests: XCTestCase { XCTAssertEqual(options.headers["Content-Type"], "application/json") XCTAssertNotNil(options.body) } + + func testMultipartFormDataBody() { + let boundary = "Boundary-\(UUID().uuidString)" + let contentType = "multipart/form-data; boundary=\(boundary)" + let options = FunctionInvokeOptions( + headers: ["Content-Type": contentType], + body: "binary value".data(using: .utf8)! + ) + XCTAssertEqual(options.headers["Content-Type"], contentType) + XCTAssertNotNil(options.body) + } } From d2fac1980cf5b589077b635d4e18249f7939a9db Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Wed, 15 Nov 2023 05:17:43 -0300 Subject: [PATCH 2/2] Bum version to 1.1.1 --- Sources/Functions/Version.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Functions/Version.swift b/Sources/Functions/Version.swift index 5e629e8..c089164 100644 --- a/Sources/Functions/Version.swift +++ b/Sources/Functions/Version.swift @@ -1 +1 @@ -let version = "1.0.0" +let version = "1.1.1"