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

fix wsproxy keepHost bug #1168

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/02.Tutorials/2.6.Websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ filters:
pools:
- servers:
- url: ws://127.0.0.1:12345
# keepHost: true, the `Host` will be the same as the original request
# If the backend is a load balancer, it would prove to be highly beneficial
keepHost: true
- url: ws://127.0.0.1:9095
- url: ws://127.0.0.1:9096
- url: ws://127.0.0.1:9097
Expand Down
5 changes: 4 additions & 1 deletion docs/07.Reference/7.02.Filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ name: proxy-example-1
pools:
- servers:
- url: ws://127.0.0.1:9095
# keepHost: true, the `Host` will be the same as the original request
# If the backend is a load balancer, it would prove to be highly beneficial
keepHost: true
- url: ws://127.0.0.1:9096
- url: ws://127.0.0.1:9097
loadBalance:
Expand Down Expand Up @@ -2165,4 +2168,4 @@ template: |
| Name | Type | Description | Required |
|------|------|-------------|----------|
| header | [httpheader.AdaptSpec](#httpheaderAdaptSpec) | Rules to revise request header | No |
| body | string | If provided the body of the original request is replaced by the value of this option. | No |
| body | string | If provided the body of the original request is replaced by the value of this option. | No |
6 changes: 6 additions & 0 deletions pkg/filters/proxies/httpproxy/wspool.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ func (sp *WebSocketServerPool) dialServer(svr *Server, req *httpprot.Request) (*
CompressionMode: websocket.CompressionDisabled,
}

// only set host when server address is not host name OR
// server is explicitly told to keep the host of the request.
if !svr.AddrIsHostName || svr.KeepHost {
opts.Host = req.Host()
}

opts.HTTPHeader.Del("Sec-WebSocket-Origin")
opts.HTTPHeader.Del("Sec-WebSocket-Protocol")
opts.HTTPHeader.Del("Sec-WebSocket-Accept")
Expand Down
Loading