forked from loafle/openapi-generator-original
Issue#15129 Feature Request Description (#16299)
Co-authored-by: Aniruddh <aniruddhjoshi94@gmail.com>
This commit is contained in:
parent
3ad3cf7dd9
commit
590430c774
@ -124,6 +124,8 @@ private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ internal class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
@ -124,6 +124,8 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else if contentType.hasPrefix("application/octet-stream"){
|
||||
encoding = OctetStreamEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
}
|
||||
@ -595,6 +597,24 @@ private class FormURLEncoding: ParameterEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
private class OctetStreamEncoding: ParameterEncoding {
|
||||
func encode(_ urlRequest: URLRequest, with parameters: [String: Any]?) throws -> URLRequest {
|
||||
|
||||
var urlRequest = urlRequest
|
||||
|
||||
var requestBodyComponents = URLComponents()
|
||||
requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:])
|
||||
|
||||
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
||||
urlRequest.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
private extension Data {
|
||||
/// Append string to Data
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user