From e22c62baba8627702ef9792fb2660fd0906d2c87 Mon Sep 17 00:00:00 2001 From: Julien Salleyron Date: Thu, 30 Apr 2020 18:00:04 +0200 Subject: [PATCH] Fix wss in x-forwarded-proto --- pkg/middlewares/forwardedheaders/forwarded_header.go | 2 +- .../forwardedheaders/forwarded_header_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/middlewares/forwardedheaders/forwarded_header.go b/pkg/middlewares/forwardedheaders/forwarded_header.go index 455e756ec..2d14ccd35 100644 --- a/pkg/middlewares/forwardedheaders/forwarded_header.go +++ b/pkg/middlewares/forwardedheaders/forwarded_header.go @@ -141,7 +141,7 @@ func (x *XForwarded) rewrite(outreq *http.Request) { } if isWebsocketRequest(outreq) { - if outreq.Header.Get(xForwardedProto) == "https" { + if outreq.Header.Get(xForwardedProto) == "https" || outreq.Header.Get(xForwardedProto) == "wss" { outreq.Header.Set(xForwardedProto, "wss") } else { outreq.Header.Set(xForwardedProto, "ws") diff --git a/pkg/middlewares/forwardedheaders/forwarded_header_test.go b/pkg/middlewares/forwardedheaders/forwarded_header_test.go index 0db1f638a..96e36442b 100644 --- a/pkg/middlewares/forwardedheaders/forwarded_header_test.go +++ b/pkg/middlewares/forwardedheaders/forwarded_header_test.go @@ -203,6 +203,17 @@ func TestServeHTTP(t *testing.T) { xForwardedProto: "wss", }, }, + { + desc: "xForwardedProto with websocket and tls and already x-forwarded-proto with wss", + tls: true, + websocket: true, + incomingHeaders: map[string]string{ + xForwardedProto: "wss", + }, + expectedHeaders: map[string]string{ + xForwardedProto: "wss", + }, + }, { desc: "xForwardedPort with explicit port", host: "foo.com:8080",