From d75c37fa7440f28110708b28d26c0cea76d4beb9 Mon Sep 17 00:00:00 2001 From: Gby56 Date: Tue, 2 Jul 2024 11:39:58 +0200 Subject: [PATCH 1/3] feat: add ff for http redirects and upstream proxying --- cmd/repeater/repeater.go | 1 + pkg/roundtrip/roudtrip.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/cmd/repeater/repeater.go b/cmd/repeater/repeater.go index 7ba1621..92952bc 100644 --- a/cmd/repeater/repeater.go +++ b/cmd/repeater/repeater.go @@ -78,6 +78,7 @@ func main() { TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, + Proxy: http.ProxyFromEnvironment, }, } } diff --git a/pkg/roundtrip/roudtrip.go b/pkg/roundtrip/roudtrip.go index b204e55..378a56f 100644 --- a/pkg/roundtrip/roudtrip.go +++ b/pkg/roundtrip/roudtrip.go @@ -2,6 +2,7 @@ package roundtrip import ( "net/http" + "os" "github.com/Escape-Technologies/repeater/pkg/logger" proto "github.com/Escape-Technologies/repeater/proto/repeater/v1" @@ -46,6 +47,15 @@ func HandleRequest(protoReq *proto.Request) *proto.Response { tls(protoReq.Url) } client := DefaultClient + + disableRedirects := os.Getenv("ESCAPE_REPEATER_DISABLE_REDIRECTS") + + if httpReq.Header.Get("X-Disable-Redirects") == "true" || disableRedirects == "1" || disableRedirects == "true" { + client.CheckRedirect = func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + } + } + mTLS := false if httpReq.Header.Get(mTLSHeader) != "" { if MTLSClient != nil { From 20446b58090930f502b9eed14e9ebc07244b6b0a Mon Sep 17 00:00:00 2001 From: Gby56 Date: Tue, 2 Jul 2024 11:50:04 +0200 Subject: [PATCH 2/3] fix: proper ff --- cmd/repeater/repeater.go | 6 ++++++ pkg/roundtrip/roudtrip.go | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/repeater/repeater.go b/cmd/repeater/repeater.go index 92952bc..663230c 100644 --- a/cmd/repeater/repeater.go +++ b/cmd/repeater/repeater.go @@ -82,6 +82,12 @@ func main() { }, } } + + disableRedirectsEnv := os.Getenv("ESCAPE_REPEATER_DISABLE_REDIRECTS") + if disableRedirectsEnv == "1" || disableRedirectsEnv == "true" { + roundtrip.DisableRedirects = true + } + logger.Info("Starting repeater client...") go logger.AlwaysConnect(url, repeaterId) diff --git a/pkg/roundtrip/roudtrip.go b/pkg/roundtrip/roudtrip.go index 378a56f..a819c37 100644 --- a/pkg/roundtrip/roudtrip.go +++ b/pkg/roundtrip/roudtrip.go @@ -2,7 +2,6 @@ package roundtrip import ( "net/http" - "os" "github.com/Escape-Technologies/repeater/pkg/logger" proto "github.com/Escape-Technologies/repeater/proto/repeater/v1" @@ -10,6 +9,7 @@ import ( var DefaultClient = &http.Client{} var MTLSClient *http.Client = nil +var DisableRedirects = false const mTLSHeader = "X-Escape-mTLS" @@ -48,9 +48,7 @@ func HandleRequest(protoReq *proto.Request) *proto.Response { } client := DefaultClient - disableRedirects := os.Getenv("ESCAPE_REPEATER_DISABLE_REDIRECTS") - - if httpReq.Header.Get("X-Disable-Redirects") == "true" || disableRedirects == "1" || disableRedirects == "true" { + if httpReq.Header.Get("X-Disable-Redirects") == "true" || DisableRedirects { client.CheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse } From 7f62873308120c685b1eb7c82295c0a976b2bbad Mon Sep 17 00:00:00 2001 From: Gby56 Date: Tue, 2 Jul 2024 11:52:50 +0200 Subject: [PATCH 3/3] fix: per-request proper ff --- pkg/roundtrip/roudtrip.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/roundtrip/roudtrip.go b/pkg/roundtrip/roudtrip.go index a819c37..705ebaa 100644 --- a/pkg/roundtrip/roudtrip.go +++ b/pkg/roundtrip/roudtrip.go @@ -52,6 +52,8 @@ func HandleRequest(protoReq *proto.Request) *proto.Response { client.CheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse } + } else { + client.CheckRedirect = nil } mTLS := false