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

Proxy protocol relative URLs #1469

Closed
badarsebard opened this issue Jun 20, 2022 · 11 comments
Closed

Proxy protocol relative URLs #1469

badarsebard opened this issue Jun 20, 2022 · 11 comments
Labels
Enhancement New feature or request Linux

Comments

@badarsebard
Copy link

badarsebard commented Jun 20, 2022

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

@badarsebard badarsebard added the Enhancement New feature or request label Jun 20, 2022
@leaanthony
Copy link
Member

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

@badarsebard
Copy link
Author

badarsebard commented Jun 21, 2022

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
Copy link
Collaborator

stffabi commented Jun 21, 2022

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.

  • Windows: Since we don't have wails:// there we use http://wails.localhost. So //fonts.googleapis.com will be requested as http://fonts.googleapis.com directly by the WebView.
  • Linux and Darwin: //fonts.googleapis.com will be requested as wails://fonts.googleapis.com directly by the WebView.

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
Copy link
Author

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
Copy link
Collaborator

stffabi commented Jun 21, 2022

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
Copy link

stale bot commented Jul 31, 2022

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.

@stale stale bot added the wontfix label Jul 31, 2022
@misitebao misitebao added wont fix This will not be worked on and removed wontfix labels Sep 18, 2022
@badarsebard
Copy link
Author

badarsebard commented Dec 17, 2022

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.

@stale stale bot removed the wont fix This will not be worked on label Dec 17, 2022
@stffabi
Copy link
Collaborator

stffabi commented Dec 17, 2022

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

See also #2109 (comment)

@leaanthony
Copy link
Member

This can now be achieved using asset server.NewProxyServer:

package main

import (
	"github.com/wailsapp/wails/v2"
	assetserver2 "github.com/wailsapp/wails/v2/pkg/assetserver"
	"github.com/wailsapp/wails/v2/pkg/options"
	"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)

func main() {
	// Create an instance of the app structure
	app := NewApp()

	// Create application with options
	err := wails.Run(&options.App{
		Title:  "externalserver",
		Width:  1024,
		Height: 768,
		AssetServer: &assetserver.Options{
			Handler: assetserver2.NewProxyServer("http://127.0.0.1:54321"),
		},
		BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
		OnStartup:        app.startup,
		Bind: []interface{}{
			app,
		},
	})

	if err != nil {
		println("Error:", err.Error())
	}
}```

@leaanthony
Copy link
Member

It would be good if this could be tested on a newer version of linux

@leaanthony
Copy link
Member

Closing for now. Please feel free to reopen if you still want this looked at 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Linux
Projects
None yet
Development

No branches or pull requests

4 participants