Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding {
var urlRequest = urlRequest

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 {
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)

return urlRequest
Expand Down
Loading
Loading