Skip to content

Commit

Permalink
Merge pull request #10 from Escape-Technologies/feat/http-redirects
Browse files Browse the repository at this point in the history
feat: add ff for http redirects and upstream proxying
  • Loading branch information
Gby56 authored Jul 2, 2024
2 parents cd0e44a + 7f62873 commit 3727bf9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/repeater/repeater.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ func main() {
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
Proxy: http.ProxyFromEnvironment,
},
}
}

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)
Expand Down
10 changes: 10 additions & 0 deletions pkg/roundtrip/roudtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

var DefaultClient = &http.Client{}
var MTLSClient *http.Client = nil
var DisableRedirects = false

const mTLSHeader = "X-Escape-mTLS"

Expand Down Expand Up @@ -46,6 +47,15 @@ func HandleRequest(protoReq *proto.Request) *proto.Response {
tls(protoReq.Url)
}
client := DefaultClient

if httpReq.Header.Get("X-Disable-Redirects") == "true" || DisableRedirects {
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
} else {
client.CheckRedirect = nil
}

mTLS := false
if httpReq.Header.Get(mTLSHeader) != "" {
if MTLSClient != nil {
Expand Down

0 comments on commit 3727bf9

Please sign in to comment.