From b0f7b7145352c89f5cec5fbe0c5e5d9ec54a5b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Wed, 10 Jun 2020 14:32:03 +0200 Subject: [PATCH] refactor X-Forwarded-Proto --- .../forwardedheaders/forwarded_header.go | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/middlewares/forwardedheaders/forwarded_header.go b/pkg/middlewares/forwardedheaders/forwarded_header.go index 4d796c55d..4bbae8a95 100644 --- a/pkg/middlewares/forwardedheaders/forwarded_header.go +++ b/pkg/middlewares/forwardedheaders/forwarded_header.go @@ -132,18 +132,18 @@ func (x *XForwarded) rewrite(outreq *http.Request) { xfProto := outreq.Header.Get(xForwardedProto) if xfProto == "" { - if outreq.TLS != nil { - outreq.Header.Set(xForwardedProto, "https") + if isWebsocketRequest(outreq) { + if outreq.TLS != nil { + outreq.Header.Set(xForwardedProto, "wss") + } else { + outreq.Header.Set(xForwardedProto, "ws") + } } else { - outreq.Header.Set(xForwardedProto, "http") - } - } - - if isWebsocketRequest(outreq) { - if outreq.Header.Get(xForwardedProto) == "https" || outreq.Header.Get(xForwardedProto) == "wss" { - outreq.Header.Set(xForwardedProto, "wss") - } else { - outreq.Header.Set(xForwardedProto, "ws") + if outreq.TLS != nil { + outreq.Header.Set(xForwardedProto, "https") + } else { + outreq.Header.Set(xForwardedProto, "http") + } } }