-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(http): media requests route to custom handlers #6540
Conversation
Looks like lint is failing, BTW. |
Core tests are failing in |
android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java
Outdated
Show resolved
Hide resolved
Why is this change applied for media files only? I think the problem is present for all file types, not just for media files, so the current change will only partly fix the issue. Also, why use a second scheme handler? We used to have multiple and we ended using only one because it had some problems (which I don't remember at the moment).
And then in the existing handler check for the |
This change is for any MIME type that is not text/JSON.
So this includes all other content types (Files, Blobs, etc.). The tricky part is that there is no way to guarantee what response type we are expecting before the request is actually executed. So to account for this, we check if 1 of these conditions are met:
|
But why not do it for text files too? I think we should do it for all regular GET requests (not for POST because in Android it's not possible to get the body), so exclude only We have another issue about a XHR call returning an Object for a JSON file instead of string and using the approach in this PR (removing the string type check) I get the string properly instead of the Object. I don't think adding the CORS headers are not needed anymore since we are using capacitor:// scheme on all requests now, it's hard to tell with the provided app, but looks like it's working fine if I remove the code. |
Shouldn't |
@@ -43,7 +48,7 @@ internal class WebViewAssetHandler: NSObject, WKURLSchemeHandler { | |||
] | |||
|
|||
// if using live reload, then set CORS headers | |||
if self.serverUrl != nil && self.serverUrl?.scheme != localUrl.scheme { | |||
if self.serverUrl != nil && self.serverUrl?.scheme != localUrl.scheme { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Addresses: #6123 and #6126
Test app: https://github.com/ItsChaceD/capacitor-http-wasm-issue
This PR routes media/non-text requests (files, blobs, WASM, etc.) to custom native protocol handlers so the responses don't have to be encoded/decoded through the bridge.
On iOS: we change the protocol from
https
tocapacitor
and it is handled by the URL scheme handlerOn Android: we take a different approach to avoid cleartext traffic issues. Instead we prepend a Capacitor Media string to the URL so that
shouldInterceptRequest
can detect that the request should be intercepted. We cannot do this on iOS since it is not allowed to intercept requests on thehttps
protocol.