File tree Expand file tree Collapse file tree 5 files changed +20
-2
lines changed
AmplifyPlugins/API/AWSAPICategoryPlugin
Amplify/Categories/API/Request Expand file tree Collapse file tree 5 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ public struct RESTOperationRequest: AmplifyOperationRequest {
18
18
/// path of the resource
19
19
public let path : String ?
20
20
21
+ /// Request headers
22
+ public let headers : [ String : String ] ?
23
+
21
24
/// Query parameters
22
25
public let queryParameters : [ String : String ] ?
23
26
@@ -30,12 +33,14 @@ public struct RESTOperationRequest: AmplifyOperationRequest {
30
33
public init ( apiName: String ? ,
31
34
operationType: RESTOperationType ,
32
35
path: String ? = nil ,
36
+ headers: [ String : String ] ? = nil ,
33
37
queryParameters: [ String : String ] ? = nil ,
34
38
body: Data ? = nil ,
35
39
options: Options ) {
36
40
self . apiName = apiName
37
41
self . operationType = operationType
38
42
self . path = path
43
+ self . headers = headers
39
44
self . queryParameters = queryParameters
40
45
self . body = body
41
46
self . options = options
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ public class RESTRequest {
16
16
/// Path of the resource
17
17
public let path : String ?
18
18
19
+ /// Headers
20
+ public let headers : [ String : String ] ?
21
+
19
22
/// Query parameters
20
23
public let queryParameters : [ String : String ] ?
21
24
@@ -24,10 +27,12 @@ public class RESTRequest {
24
27
25
28
public init ( apiName: String ? = nil ,
26
29
path: String ? = nil ,
30
+ headers: [ String : String ] ? = nil ,
27
31
queryParameters: [ String : String ] ? = nil ,
28
32
body: Data ? = nil ) {
29
33
self . apiName = apiName
30
34
self . path = path
35
+ self . headers = headers
31
36
self . queryParameters = queryParameters
32
37
self . body = body
33
38
}
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ RESTOperation {
93
93
// Construct URL Request with url and request body
94
94
let urlRequest = RESTOperationRequestUtils . constructURLRequest ( with: url,
95
95
operationType: request. operationType,
96
+ headers: request. headers,
96
97
requestPayload: request. body)
97
98
98
99
// Intercept request
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ extension RESTOperationRequest {
12
12
self = RESTOperationRequest ( apiName: request. apiName,
13
13
operationType: operationType,
14
14
path: request. path,
15
+ headers: request. headers,
15
16
queryParameters: request. queryParameters,
16
17
body: request. body,
17
18
options: RESTOperationRequest . Options ( ) )
Original file line number Diff line number Diff line change @@ -51,11 +51,17 @@ final class RESTOperationRequestUtils {
51
51
// Construct a request specific to the `RESTOperationType`
52
52
static func constructURLRequest( with url: URL ,
53
53
operationType: RESTOperationType ,
54
+ headers: [ String : String ] ? ,
54
55
requestPayload: Data ? ) -> URLRequest {
55
56
56
57
var baseRequest = URLRequest ( url: url)
57
- let headers = [ " content-type " : " application/json " ]
58
- baseRequest. allHTTPHeaderFields = headers
58
+ var requestHeaders = [ " content-type " : " application/json " ]
59
+ if let headers = headers {
60
+ for (key, value) in headers {
61
+ requestHeaders [ key] = value
62
+ }
63
+ }
64
+ baseRequest. allHTTPHeaderFields = requestHeaders
59
65
baseRequest. httpMethod = operationType. rawValue
60
66
baseRequest. httpBody = requestPayload
61
67
return baseRequest
You can’t perform that action at this time.
0 commit comments