You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use the Amplify API plugin to make multipart/form-data requests to API Gateway. From documentation listed here[1], I'd have expected to be able to do the following:
let headers = ["content-type": "multipart/form-data; boundary=....."]
let request = RESTRequest(path: ...., headers: headers, body: ...)
Ideally this would allow me to pass in the custom content-type while constructing a RESTRequest object[2], and then eventually override the default application/json content-type used while constructing a URLRequest object[3].
However, when the interceptors are run the AuthTokenURLInterceptor kicks and always overwrites the content-type header to set it to application/json [4, 5].
Is there a reason the AuthTokenURLInterceptor needs to set content-type?
As a workaround, I could just create another URLInterceptor and set the Content-Type there but given that the rest of the Amplify library is set up to accept custom headers it seems redundant to do that.
URLRequest in AWSRESTOperation before AuthTokenURLInterceptor runs:
Printing description of urlRequest:
▿ ...
▿ httpMethod : Optional<String>
- some : "POST"
▿ allHTTPHeaderFields : Optional<Dictionary<String, String>>
▿ some : 2 elements
▿ 0 : 2 elements
- key : "Cache-Control"
- value : "no-store"
▿ 1 : 2 elements
- key : "Content-Type"
- value : "multipart/form-data; boundary=CC1F1DBE-9CC3-448E-AE78-A1782C9D2BED"
▿ httpBody : Optional<Data>
▿ some : 2051407 bytes
- count : 2051407
▿ pointer : 0x00007f7bfc821000
- pointerValue : 140170494087168
- httpBodyStream : nil
- httpShouldHandleCookies : true
- httpShouldUsePipelining : false
URLRequest in AWSRESTOperation after AuthTokenURLInterceptor runs:
Printing description of finalRequest:
▿ ....
▿ httpMethod : Optional<String>
- some : "POST"
▿ allHTTPHeaderFields : Optional<Dictionary<String, String>>
▿ some : 5 elements
▿ 0 : 2 elements
- key : "User-Agent"
- value : "amplify-iOS/1.16.1 iOS/16.4 en_US"
▿ 1 : 2 elements
- key : "Cache-Control"
- value : "no-store"
▿ 2 : 2 elements
- key : "Authorization"
- value : "...."
▿ 3 : 2 elements
- key : "Content-Type"
- value : "application/json"
▿ 4 : 2 elements
- key : "X-Amz-Date"
- value : "20230828T103145Z"
▿ httpBody : Optional<Data>
▿ some : 2051407 bytes
- count : 2051407
▿ pointer : 0x00007f7bfc821000
- pointerValue : 140170494087168
- httpBodyStream : nil
- httpShouldHandleCookies : true
- httpShouldUsePipelining : false
Steps To Reproduce
See above.
Expected behavior
Overriding Content-Type should work in RESTRequest should work.
Amplify Framework Version
2.15.2
Amplify Categories
API
Dependency manager
Swift PM
Swift version
5.8.1
CLI version
12.2.5
Xcode version
14.3.1
Relevant log output
No response
Is this a regression?
No
Regression additional context
No response
Platforms
iOS
OS Version
All
Device
All
Specific to simulators
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
sandeepklr
changed the title
AuthTokenURLInterceptor overriding Content-Type header
AuthTokenURLInterceptor overriding Content-Type header to application/json always
Aug 28, 2023
Describe the bug
Relevant amplifyconfiguration.json api configuration blob:
I'm trying to use the Amplify API plugin to make
multipart/form-data
requests to API Gateway. From documentation listed here[1], I'd have expected to be able to do the following:Ideally this would allow me to pass in the custom content-type while constructing a RESTRequest object[2], and then eventually override the default
application/json
content-type used while constructing a URLRequest object[3].However, when the interceptors are run the AuthTokenURLInterceptor kicks and always overwrites the content-type header to set it to
application/json
[4, 5].Is there a reason the AuthTokenURLInterceptor needs to set content-type?
As a workaround, I could just create another URLInterceptor and set the Content-Type there but given that the rest of the Amplify library is set up to accept custom headers it seems redundant to do that.
[1] https://docs.amplify.aws/lib/restapi/authz/q/platform/ios/#none
[2]
amplify-swift/Amplify/Categories/API/Request/RESTRequest.swift
Lines 35 to 39 in 9d6fa8b
[3]
amplify-swift/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/RESTOperationRequestUtils.swift
Lines 61 to 66 in 9d6fa8b
[4]
amplify-swift/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenURLRequestInterceptor.swift
Lines 35 to 36 in 9d6fa8b
[5] Debug details:
URLRequest in AWSRESTOperation before AuthTokenURLInterceptor runs:
URLRequest in AWSRESTOperation after AuthTokenURLInterceptor runs:
Steps To Reproduce
See above.
Expected behavior
Overriding Content-Type should work in RESTRequest should work.
Amplify Framework Version
2.15.2
Amplify Categories
API
Dependency manager
Swift PM
Swift version
5.8.1
CLI version
12.2.5
Xcode version
14.3.1
Relevant log output
No response
Is this a regression?
No
Regression additional context
No response
Platforms
iOS
OS Version
All
Device
All
Specific to simulators
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: