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/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" 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) + } }