@marcel91200 / caddy Mirror · read-only / commits / 328fb614
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 04:30 UTC

reverseproxy: Only handle websocket protocol (#6740)

bt90 committed Dec 11, 2024 at 19:17 UTC 328fb614f0e9996b184f41d59b7092c21dd9c712
1 file changed +2 -2
modules/caddyhttp/reverseproxy/reverseproxy.go
+2 -2
@@ -398,13 +398,13 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
398 }
399 // websocket over http2, assuming backend doesn't support this, the request will be modified to http1.1 upgrade
400 // TODO: once we can reliably detect backend support this, it can be removed for those backends
401 - if r.ProtoMajor == 2 && r.Method == http.MethodConnect && r.Header.Get(":protocol") != "" {
401 + if r.ProtoMajor == 2 && r.Method == http.MethodConnect && r.Header.Get(":protocol") == "websocket" {
402 clonedReq.Header.Del(":protocol")
403 // keep the body for later use. http1.1 upgrade uses http.NoBody
404 caddyhttp.SetVar(clonedReq.Context(), "h2_websocket_body", clonedReq.Body)
405 clonedReq.Body = http.NoBody
406 clonedReq.Method = http.MethodGet
407 - clonedReq.Header.Set("Upgrade", r.Header.Get(":protocol"))
407 + clonedReq.Header.Set("Upgrade", "websocket")
408 clonedReq.Header.Set("Connection", "Upgrade")
409 key := make([]byte, 16)
410 _, randErr := rand.Read(key)