Skip to content

Conversation

@frederikbosch
Copy link

Since Capacitor 8.0 data: requests throw because NSURLResponse is not a HTTPURLRepsonse

data: request throw because NSURLResponse is not a HTTPURLRepsonse
@theproducer
Copy link
Contributor

Thanks @frederikbosch! Do you have a reproduction for this issue, or can it be seen in basically any minimal project that uses CapacitorHttp?

@frederikbosch
Copy link
Author

frederikbosch commented Jan 12, 2026

@theproducer I don't at the moment. I have upgraded my app from 7 to 8 and I got crashes because of the forced casts. It might very well be that because of some other upgrades that I only now started with data: URI requests.

That data URIs fail can be proven quite easily by this SwiftFiddle.

Moreover, it is kind of documented behavior. The URLSession.dataTask method documentation says:

If you are making an HTTP or HTTPS request, the returned object is actually an HTTPURLResponse object.

And a data: URI request is not a HTTP request. But documentation is not clear what the response is if the request is not a HTTP(S) request, but apparently it is a NSURLResponse.

@theproducer theproducer self-assigned this Jan 12, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Jan 13, 2026
@frederikbosch
Copy link
Author

@markemer Much better to unpack the response optional, I have updated the PR.

riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Jan 14, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Jan 15, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Jan 16, 2026
@theproducer theproducer changed the title Fix throwing data URI requests fix(http): Fix throwing data URI requests on iOS Jan 21, 2026

let type = ResponseType(rawValue: responseType) ?? .default
call.resolve(self.buildResponse(data, response, responseType: type))
} else if let response = response as? NSURLResponse {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to rename NSURLResponse to URLResponse here as well.
Screenshot 2026-01-21 at 10 58 18 AM

Screenshot 2026-01-21 at 10 56 25 AM

@theproducer theproducer requested a review from a team January 21, 2026 16:59
@jcesarmobile
Copy link
Member

Can you give a bit more information about what are you doing to get the crash?

Are you getting it while doing regular fetch/XHR calls with http plugin enabled?
Or are you calling the CapacitorHttp plugin API directly like CapacitorHttp.get({url: 'data:text/plain;base64,SGVsbG8='})?

If you are doing fetch/XHR calls and you get the crash, could you provide a sample app that reproduces the issue?
I've not been able to get the crash while doing that.

If you are doing CapacitorHttp plugin API calls to data urls, while it shouldn't crash, it shouldn't work neither. CapacitorHttp plugin is to avoid CORS problems, and all methods description include "make a Request to a server", so should only be used with http/https urls, not with data urls.
I've tested this and it makes the plugin crash on iOS, but on Android it returns an error saying data urls are not supported, iOS should also do this instead of crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants