Skip to content
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

feat(ios): add http(s) proxy/scheme #448

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

NiklasMerz
Copy link
Contributor

This adds a new URLSchemeHandler which can proxy http(s) requests to external servers.
This is useful for some CORS issues and webview bugs that affect the use of cookies in CORS requests via XHR and fetch.

See Webkit bug https://bugs.webkit.org/show_bug.cgi?id=200857

For that reason cookies will be synced between proxied requests on the native layer and the webview.

@NiklasMerz
Copy link
Contributor Author

If this feature is usefull and gets merged, the documentation needs to be updated probably here: https://beta.ionicframework.com/docs/building/webview#file-protocol ?

@fabrodz
Copy link

fabrodz commented Oct 3, 2019

I'm running tests over iOS 13.1.2 and the cookies doesn't reach the server in fetch requests, i.e. <img src="https://mydomain.com/img.jpg" />, but I don't know if there are some kind of configuration or function must need to call before the html is rendered.

@NiklasMerz
Copy link
Contributor Author

NiklasMerz commented Oct 3, 2019

You must use the convertFileSrc Javascript function to convert your URLs for using the proxy

@NiklasMerz
Copy link
Contributor Author

This was done with some suggestions from @jcesarmobile . Do you have any comments on the implementation?

@NiklasMerz
Copy link
Contributor Author

This is the corresponding documentation that needs to be updated in case this gets merged: https://github.com/ionic-team/ionic-docs/blob/master/src/pages/building/webview.md

@NiklasMerz NiklasMerz mentioned this pull request Oct 5, 2019
@NiklasMerz
Copy link
Contributor Author

Seems like #376 is the Android version of this change. Adding this feature may mean integrating both PRs.

This adds a new URLSchemeHandler which can proxy http(s) requests to external servers.
This is useful for some CORS issues and webview bugs that affect the use of cookies in CORS requests via XHR and fetch.
For that reason cookies will be synced between proxied requests on the native layer and the webview.
@NiklasMerz
Copy link
Contributor Author

I just rebased and resolved conflicts with cbd526d

@NiklasMerz
Copy link
Contributor Author

Documentation needs to be updated. For basic instrutions see this: #475 (comment)

@NiklasMerz
Copy link
Contributor Author

NiklasMerz commented Nov 28, 2019

@jcesarmobile Do you see any chances this could be merged? I don't know how relevant this is for the upstream plugin, but I try to mimize forked plugins in our app.

I now know this breaks Anroid currently.

Proxying http and https via `convertFileSrc` only works on Android where
the webview runs on custom schemes.
Copy link

@srbala srbala left a comment

Choose a reason for hiding this comment

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

@NiklasMerz it might be good idea keep the boolean check first in IF statement

if (convertHttp && url.startsWith('http://'))
AND
if (convertHttp && url.startsWith('https://'))

What do you think?

@alexsasharegan
Copy link

I tried running this, and it seems to reliably crash my iOS app. Not sure how to provide more info.

@NiklasMerz
Copy link
Contributor Author

@alexsasharegan You could open you iOS platform in Xcode and run it from there on an iPhone. If the app crashes, you should see an error in the Xcode consoe.

@GroupeBEL GroupeBEL mentioned this pull request Mar 30, 2020
@GroupeBEL
Copy link

@NiklasMerz can you please resolve the conflict and thanks ^_^

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