forked from loafle/openapi-generator-original
Fixes URLSessionImplementations template for swift generator (#20381)
This commit is contained in:
parent
25283d46a7
commit
93158ea4dc
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
|
|||||||
var urlRequest = urlRequest
|
var urlRequest = urlRequest
|
||||||
|
|
||||||
var requestBodyComponents = URLComponents()
|
var requestBodyComponents = URLComponents()
|
||||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||||
|
|
||||||
|
/// `httpBody` needs to be percent encoded
|
||||||
|
/// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
||||||
|
/// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded"
|
||||||
|
let percentEncodedQueryItems = queryItems?.compactMap { queryItem in
|
||||||
|
return URLQueryItem(
|
||||||
|
name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name,
|
||||||
|
value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.value)
|
||||||
|
}
|
||||||
|
requestBodyComponents.queryItems = percentEncodedQueryItems
|
||||||
|
|
||||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign
|
||||||
|
/// that is why we do the percent encoding manually for each key/value pair
|
||||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||||
|
|
||||||
return urlRequest
|
return urlRequest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user