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 {
1818 /// path of the resource
1919 public let path : String ?
2020
21+ /// Request headers
22+ public let headers : [ String : String ] ?
23+
2124 /// Query parameters
2225 public let queryParameters : [ String : String ] ?
2326
@@ -30,12 +33,14 @@ public struct RESTOperationRequest: AmplifyOperationRequest {
3033 public init ( apiName: String ? ,
3134 operationType: RESTOperationType ,
3235 path: String ? = nil ,
36+ headers: [ String : String ] ? = nil ,
3337 queryParameters: [ String : String ] ? = nil ,
3438 body: Data ? = nil ,
3539 options: Options ) {
3640 self . apiName = apiName
3741 self . operationType = operationType
3842 self . path = path
43+ self . headers = headers
3944 self . queryParameters = queryParameters
4045 self . body = body
4146 self . options = options
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ public class RESTRequest {
1616 /// Path of the resource
1717 public let path : String ?
1818
19+ /// Headers
20+ public let headers : [ String : String ] ?
21+
1922 /// Query parameters
2023 public let queryParameters : [ String : String ] ?
2124
@@ -24,10 +27,12 @@ public class RESTRequest {
2427
2528 public init ( apiName: String ? = nil ,
2629 path: String ? = nil ,
30+ headers: [ String : String ] ? = nil ,
2731 queryParameters: [ String : String ] ? = nil ,
2832 body: Data ? = nil ) {
2933 self . apiName = apiName
3034 self . path = path
35+ self . headers = headers
3136 self . queryParameters = queryParameters
3237 self . body = body
3338 }
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ RESTOperation {
9393 // Construct URL Request with url and request body
9494 let urlRequest = RESTOperationRequestUtils . constructURLRequest ( with: url,
9595 operationType: request. operationType,
96+ headers: request. headers,
9697 requestPayload: request. body)
9798
9899 // Intercept request
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ extension RESTOperationRequest {
1212 self = RESTOperationRequest ( apiName: request. apiName,
1313 operationType: operationType,
1414 path: request. path,
15+ headers: request. headers,
1516 queryParameters: request. queryParameters,
1617 body: request. body,
1718 options: RESTOperationRequest . Options ( ) )
Original file line number Diff line number Diff line change @@ -51,11 +51,17 @@ final class RESTOperationRequestUtils {
5151 // Construct a request specific to the `RESTOperationType`
5252 static func constructURLRequest( with url: URL ,
5353 operationType: RESTOperationType ,
54+ headers: [ String : String ] ? ,
5455 requestPayload: Data ? ) -> URLRequest {
5556
5657 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
5965 baseRequest. httpMethod = operationType. rawValue
6066 baseRequest. httpBody = requestPayload
6167 return baseRequest
You can’t perform that action at this time.
0 commit comments