wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
24.76k stars 1.18k forks source link

Proxy protocol relative URLs #1469

Open badarsebard opened 2 years ago

badarsebard commented 2 years ago

Is your feature request related to a problem? Please describe.

I am creating an email client and rendering HTML emails using an iframe. When the HTML content uses a protocol relative URL (e.g. //fonts.googleapis.com) the application attempts to use the wails: protocol and an error is returned.

Describe the solution you'd like

Is there some way to proxy requests made to the application? So when the browser code makes the request to wails:// the app will forward it on to http:// and then return the correct response?

Describe alternatives you've considered

No response

Additional context

No response

leaanthony commented 2 years ago

You could use a custom Assethandler for this https://wails.io/docs/reference/options/#assetshandler-

badarsebard commented 2 years ago

This looks like it will work, but when I test it I run into this error

2022-06-20 16:44:08.95853383 -0400 EDT assetserver.go:116 ProcessHTTPRequest(): ERROR | [AssetServer] Error processing request 'wails://fonts.googleapis.com/css?family=Google+Sans': Expected host '%!d(string=wails)' in request, but was 'fonts.googleapis.com' (HttpResponse=500)

Tracing this back I find it's from code found in v2/internal/frontend/desktop/linux/frontend.go:337

stffabi commented 2 years ago

Currently AssetsHandler are supposed to be called only for requests that target the Wails assets. Changing this behaviour would lead to some inconsistency between the platforms.

We already have som inconsistency there, but AssetsHandler won't be called currently on any platform for //fonts.googleapis.com so at least that's consistent. It would be only possible to call AssetsHandler on Linux and Darwin but not on Windows (as long was we can't use wails:// there). So we would need to wait until we can use wails:// on Windows to have a consistent behaviour. Another possibility would be internally redirect wails://somehost to http://somehost. But at the moment we can't do redirects on Linux because ResponseStatus Codes are only supported beginning with WebKitGTK >= 2.36 (current minimum target is older).

badarsebard commented 2 years ago

So in the Windows case, the current behavior ends up being the desired http://fonts.googleapis.com (albeit as a consequence of being unable to register the wails: scheme). For linux/darwin, specifying a redirect of the protocol is exactly what is needed. I can understand that the intent of the AssetsHandler is to specifically handle the assets served by the wails application and not external ones.

Given that Wails is designed to utilize web frameworks for its frontend I think it would be useful to have an option or mechanism to control or proxy all requests that come in over the wails scheme. Understandably this is a fairly edge case given that URLs that include the http/s scheme will function correctly, and it's only these protocol relative ones that cause a problem.

stffabi commented 2 years ago

Personally I would opt to internally return a 308-redirect for anything that comes in to wails: scheme that is not the wails host to http://host. We plan to add support for WebKitGTK >= 2.36 in the near future, so we would be able to do those redirects also on Linux. A question to be answered for 2.36 support is, if one should just bump the minimal dependency or pin the binary minimal dependency against the WebKitGTK version that was used to compile it.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

badarsebard commented 1 year ago

Personally I would opt to internally return a 308-redirect for anything that comes in to wails: scheme that is not the wails host to http://host. We plan to add support for WebKitGTK >= 2.36 in the near future, so we would be able to do those redirects also on Linux. A question to be answered for 2.36 support is, if one should just bump the minimal dependency or pin the binary minimal dependency against the WebKitGTK version that was used to compile it.

Now that #2151 has been merged the 308 redirect should be possible. This issue got marked stale due to age.

stffabi commented 1 year ago

Unfortunately WebKit2GTK 2.36+ still has no support for http redirects.

See also https://github.com/wailsapp/wails/issues/2109#issuecomment-1325740848