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

Dialer's Header parameter doesn't work as intended #170

Closed
Gekko0114 opened this issue May 10, 2023 · 6 comments · Fixed by #196
Closed

Dialer's Header parameter doesn't work as intended #170

Gekko0114 opened this issue May 10, 2023 · 6 comments · Fixed by #196

Comments

@Gekko0114
Copy link

Hello Gobwas,

Thanks for the great package!

I found that httpWriteUpgradeRequest doesn't work as intended.
When I try to add dial function like this:

		dialer := &ws.Dialer{
			Header:  ws.HandshakeHeaderHTTP(h),
		}

I want to assign request's header to h, but it doesn't work as expected due to this code httpWriteHeader(bw, headerHost, u.Host).
This causes both h and u.Host to be assigned to the request's header.

I hope this problem can be resolved soon.
Thanks,

FYI
We discussed this problem in this PR.

@cristaloleg
Copy link
Collaborator

Thanks for the info, will take a look shortly. Do you have a fix (even a theoretical) for that btw ?

@Gekko0114
Copy link
Author

You can fix it by replacing httpWriteHeader(bw, headerHost, u.Host) with the following code:

	host := u.Host
	if headerHTTP, ok := header.(HandshakeHeaderHTTP); ok {
		httpHeaderHTTP := http.Header(headerHTTP)
		if v := httpHeaderHTTP.Get(headerHost); v != "" {
			host = v
		}
	}

	httpWriteHeader(bw, headerHost, host)

And you need to comment out https://github.com/gobwas/ws/blob/master/http.go#L323-L325.

However, since handshakeheader is an interface, so I don't think my code is a perfect solution.
My solution is specific to HandshakeHeaderHTTP type.

I think you should decide how to fix it because this solution is related to this library's design itself.

@matthyx
Copy link

matthyx commented Dec 22, 2023

@cristaloleg have you looked at this?

@cristaloleg
Copy link
Collaborator

Yes, but AFAIR we didn't found a solution. Feel free to make a PR.

@matthyx
Copy link

matthyx commented Dec 22, 2023

Yes, but AFAIR we didn't found a solution. Feel free to make a PR.

Please have a look at: #194
Merry Christmas!

@cristaloleg
Copy link
Collaborator

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 a pull request may close this issue.

3 participants