[swift] [urlsession] Fixes crash for uploads with content-type "image/" (#21544)

* Fix image upload for content-type image

* update samples

* add test case in spec and update samples

* update bitrise stack so we get xcpretty 0.4.1

* Revert "add test case in spec and update samples"

This reverts commit 92202dd8506b2482cda69fe1d95a61d5a51881e3.
This commit is contained in:
Jonas Reichert 2025-07-15 10:25:34 +02:00 committed by GitHub
parent ca8c6d2f5d
commit f9098d5a89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 24 additions and 24 deletions

View File

@ -48,4 +48,4 @@ workflows:
meta:
bitrise.io:
stack: osx-xcode-16.0.x
stack: osx-xcode-16.3.x

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ 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"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ internal class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendab
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")

View File

@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
encoding = FormURLEncoding()
} else if contentType.hasPrefix("application/octet-stream"){
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
encoding = OctetStreamEncoding()
} else {
fatalError("Unsupported Media Type - \(contentType)")