[swift5] support content types with charsets (#13981)

* enable possibility to add charset to content-type

* update samples
This commit is contained in:
Jonas Reichert
2022-11-10 15:28:36 +01:00
committed by GitHub
parent d8bed4228d
commit 7ad9f835ff
17 changed files with 51 additions and 51 deletions

View File

@@ -96,9 +96,9 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = nil
let upload = manager.upload(multipartFormData: { mpForm in
@@ -134,7 +134,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
requestTask.set(request: upload)
self.processRequest(request: upload, managerId, apiResponseQueue, completion)
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = URLEncoding(destination: .httpBody)
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -96,9 +96,9 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = nil
let upload = manager.upload(multipartFormData: { mpForm in
@@ -134,7 +134,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
requestTask.set(request: upload)
self.processRequest(request: upload, managerId, apiResponseQueue, completion)
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = URLEncoding(destination: .httpBody)
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ internal class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
case .options, .post, .put, .patch, .delete, .trace, .connect:
let contentType = headers["Content-Type"] ?? "application/json"
if contentType == "application/json" {
if contentType.hasPrefix("application/json") {
encoding = JSONDataEncoding()
} else if contentType == "multipart/form-data" {
} else if contentType.hasPrefix("multipart/form-data") {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType == "application/x-www-form-urlencoded" {
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")