Skip to content

Commit

Permalink
Fix for websocket connections (#80)
Browse files Browse the repository at this point in the history
### Description

HTTP protocol upgrades are only valid with HTTP/1.1. Disregard the value
of `backendProto` when `upgrade` is present in the `connection` header.

### Type of change

* [ ] New feature
* [ ] Feature improvement
* [x] Bug fix
* [ ] Documentation
* [ ] Cleanup / refactoring
* [ ] Other (please explain)

### How is this change tested ?

* [ ] Unit tests
* [x] Manual tests (explain)
* [ ] Tests are not needed
  • Loading branch information
rthellend authored Jan 28, 2024
1 parent e2ce5d2 commit d917d5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# TLSPROXY Release Notes

* Fix WebSocket connections when `backendProto` is set to something other than `http/1.1`.

## v0.6.0

* Starting with v0.6.0, tlsproxy is built with QUIC & HTTP/3 support by default. Binaries without QUIC can still be built with `-tags noquic`.
Expand Down
8 changes: 8 additions & 0 deletions proxy/backend-http.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ func (be *Backend) reverseProxyTransport() http.RoundTripper {
if proto == "" && req.TLS != nil && req.TLS.NegotiatedProtocol != "" {
proto = req.TLS.NegotiatedProtocol
}
if req.ProtoMajor == 1 {
for _, hdr := range strings.Split(req.Header.Get("connection"), ",") {
// Connection upgrades, e.g. websocket, must use http/1.1.
if strings.ToLower(strings.TrimSpace(hdr)) == "upgrade" {
proto = "http/1.1"
}
}
}
if proto == "h3" && h3 != nil {
return h3.RoundTrip(req)
}
Expand Down

0 comments on commit d917d5b

Please sign in to comment.