File tree 2 files changed +16
-5
lines changed
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -18,23 +18,23 @@ public struct FunctionInvokeOptions {
18
18
let body : Data ?
19
19
20
20
public init ( method: Method ? = nil , headers: [ String : String ] = [ : ] , body: some Encodable ) {
21
- var headers = headers
21
+ var defaultHeaders = [ String : String ] ( )
22
22
23
23
switch body {
24
24
case let string as String :
25
- headers [ " Content-Type " ] = " text/plain "
25
+ defaultHeaders [ " Content-Type " ] = " text/plain "
26
26
self . body = string. data ( using: . utf8)
27
27
case let data as Data :
28
- headers [ " Content-Type " ] = " application/octet-stream "
28
+ defaultHeaders [ " Content-Type " ] = " application/octet-stream "
29
29
self . body = data
30
30
default :
31
31
// default, assume this is JSON
32
- headers [ " Content-Type " ] = " application/json "
32
+ defaultHeaders [ " Content-Type " ] = " application/json "
33
33
self . body = try ? JSONEncoder ( ) . encode ( body)
34
34
}
35
35
36
36
self . method = method
37
- self . headers = headers
37
+ self . headers = defaultHeaders . merging ( headers) { _ , new in new }
38
38
}
39
39
40
40
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 {
23
23
XCTAssertEqual ( options. headers [ " Content-Type " ] , " application/json " )
24
24
XCTAssertNotNil ( options. body)
25
25
}
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
+ }
26
37
}
You can’t perform that action at this time.
0 commit comments