summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/streaming.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-04-11 14:49:56 -0400
committerGitHub <noreply@github.com>2022-04-11 12:49:56 -0600
commite4ce40f8ff0424054045de2461fc7228c66f3c61 (patch)
tree0e1ea3df9d240c52b5819c5881bbb45af7d0354f /modules/caddyhttp/reverseproxy/streaming.go
parentafca2421112eb89e435888f50f8146364a3c60a4 (diff)
reverseproxy: Sync up `handleUpgradeResponse` with stdlib (#4664)
* reverseproxy: Sync up `handleUpgradeResponse` with stdlib I had left this as a TODO for when we bump to minimum 1.17, but I should've realized it was under `internal` so it couldn't be used directly. Copied the functions we needed for parity. Hopefully this is ok! * Add tests and fix godoc comments Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
Diffstat (limited to 'modules/caddyhttp/reverseproxy/streaming.go')
-rw-r--r--modules/caddyhttp/reverseproxy/streaming.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/modules/caddyhttp/reverseproxy/streaming.go b/modules/caddyhttp/reverseproxy/streaming.go
index 1db352b..6bd1af2 100644
--- a/modules/caddyhttp/reverseproxy/streaming.go
+++ b/modules/caddyhttp/reverseproxy/streaming.go
@@ -32,10 +32,15 @@ import (
func (h Handler) handleUpgradeResponse(logger *zap.Logger, rw http.ResponseWriter, req *http.Request, res *http.Response) {
reqUpType := upgradeType(req.Header)
resUpType := upgradeType(res.Header)
- // TODO: Update to use "net/http/internal/ascii" once we bumped
- // the minimum Go version to 1.17.
- // See https://github.com/golang/go/commit/5c489514bc5e61ad9b5b07bd7d8ec65d66a0512a
- if reqUpType != resUpType {
+
+ // Taken from https://github.com/golang/go/commit/5c489514bc5e61ad9b5b07bd7d8ec65d66a0512a
+ // We know reqUpType is ASCII, it's checked by the caller.
+ if !asciiIsPrint(resUpType) {
+ h.logger.Debug("backend tried to switch to invalid protocol",
+ zap.String("backend_upgrade", resUpType))
+ return
+ }
+ if !asciiEqualFold(reqUpType, resUpType) {
h.logger.Debug("backend tried to switch to unexpected protocol via Upgrade header",
zap.String("backend_upgrade", resUpType),
zap.String("requested_upgrade", reqUpType))