File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -18,23 +18,23 @@ public struct FunctionInvokeOptions {
1818 let body : Data ?
1919
2020 public init ( method: Method ? = nil , headers: [ String : String ] = [ : ] , body: some Encodable ) {
21- var headers = headers
21+ var defaultHeaders = [ String : String ] ( )
2222
2323 switch body {
2424 case let string as String :
25- headers [ " Content-Type " ] = " text/plain "
25+ defaultHeaders [ " Content-Type " ] = " text/plain "
2626 self . body = string. data ( using: . utf8)
2727 case let data as Data :
28- headers [ " Content-Type " ] = " application/octet-stream "
28+ defaultHeaders [ " Content-Type " ] = " application/octet-stream "
2929 self . body = data
3030 default :
3131 // default, assume this is JSON
32- headers [ " Content-Type " ] = " application/json "
32+ defaultHeaders [ " Content-Type " ] = " application/json "
3333 self . body = try ? JSONEncoder ( ) . encode ( body)
3434 }
3535
3636 self . method = method
37- self . headers = headers
37+ self . headers = defaultHeaders . merging ( headers) { _ , new in new }
3838 }
3939
4040 public init ( method: Method ? = nil , headers: [ String : String ] = [ : ] ) {
Original file line number Diff line number Diff line change @@ -23,4 +23,15 @@ final class FunctionInvokeOptionsTests: XCTestCase {
2323 XCTAssertEqual ( options. headers [ " Content-Type " ] , " application/json " )
2424 XCTAssertNotNil ( options. body)
2525 }
26+
27+ func testMultipartFormDataBody( ) {
28+ let boundary = " Boundary- \( UUID ( ) . uuidString) "
29+ let contentType = " multipart/form-data; boundary= \( boundary) "
30+ let options = FunctionInvokeOptions (
31+ headers: [ " Content-Type " : contentType] ,
32+ body: " binary value " . data ( using: . utf8) !
33+ )
34+ XCTAssertEqual ( options. headers [ " Content-Type " ] , contentType)
35+ XCTAssertNotNil ( options. body)
36+ }
2637}
You can’t perform that action at this time.
0 commit comments