Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Revert "Use AcceptResponseHandler in goproxy https CONNECT hook (stri…
Browse files Browse the repository at this point in the history
…pe#199)"

This reverts commit 4587d68.
  • Loading branch information
matt-intercom authored Jan 4, 2024
1 parent 885891b commit 394167f
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 55 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/rs/xid v1.2.1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.0
github.com/stripe/goproxy v0.0.0-20230801191332-fabc3ecb7251
github.com/stripe/goproxy v0.0.0-20220308202309-3f1dfba6d1a4
golang.org/x/net v0.7.0
gopkg.in/urfave/cli.v1 v1.20.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stripe/goproxy v0.0.0-20220308202309-3f1dfba6d1a4 h1:6lqpRCXAhigpiMu6aZYTHryDmLrhIND0H4iUKEntN1M=
github.com/stripe/goproxy v0.0.0-20220308202309-3f1dfba6d1a4/go.mod h1:hF2CVgH4++5ijZiy9grGVP8Fsi4u+SMOtbnIKYbMUjY=
github.com/stripe/goproxy v0.0.0-20230801191332-fabc3ecb7251 h1:wR1exp7OglR0ctk8yWPVp1oTOuyaLUlJv3/Wlbvbw64=
github.com/stripe/goproxy v0.0.0-20230801191332-fabc3ecb7251/go.mod h1:hF2CVgH4++5ijZiy9grGVP8Fsi4u+SMOtbnIKYbMUjY=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
4 changes: 2 additions & 2 deletions pkg/smokescreen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ type Config struct {
// Custom handler to allow clients to modify reject responses
RejectResponseHandler func(*http.Response)

// Custom handler to allow clients to modify successful CONNECT responses
AcceptResponseHandler func(*smokescreenContext, *http.Response) error
// Custom handler to allow clients to modify accept responses
AcceptResponseHandler func(*http.Response)

// UnsafeAllowPrivateRanges inverts the default behavior, telling smokescreen to allow private IP
// ranges by default (exempting loopback and unicast ranges)
Expand Down
15 changes: 1 addition & 14 deletions pkg/smokescreen/smokescreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func BuildProxy(config *Config) *goproxy.ProxyHttpServer {
resp.Header.Del(errorHeader)
}
if sctx.cfg.AcceptResponseHandler != nil {
sctx.cfg.AcceptResponseHandler(sctx, resp)
sctx.cfg.AcceptResponseHandler(resp)
}
}

Expand All @@ -559,19 +559,6 @@ func BuildProxy(config *Config) *goproxy.ProxyHttpServer {
logProxy(config, pctx)
return resp
})

// This function will be called on the response to a successful https CONNECT request.
// The goproxy OnResponse() function above is only called for non-https responses.
if config.AcceptResponseHandler != nil {
proxy.ConnectRespHandler = func(pctx *goproxy.ProxyCtx, resp *http.Response) error {
sctx, ok := pctx.UserData.(*smokescreenContext)
if !ok {
return fmt.Errorf("goproxy ProxyContext missing required UserData *smokescreenContext")
}
return config.AcceptResponseHandler(sctx, resp)
}
}

return proxy
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/smokescreen/smokescreen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,8 @@ func TestAcceptResponseHandler(t *testing.T) {
cfg, err := testConfig("test-local-srv")

// set a custom AcceptResponseHandler that will set a header on every reject response
cfg.AcceptResponseHandler = func(_ *smokescreenContext, resp *http.Response) error {
cfg.AcceptResponseHandler = func(resp *http.Response) {
resp.Header.Set(testHeader, "This header is added by the AcceptResponseHandler")
return nil
}
r.NoError(err)

Expand Down
30 changes: 1 addition & 29 deletions vendor/github.com/stripe/goproxy/https.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions vendor/github.com/stripe/goproxy/proxy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ github.com/sirupsen/logrus/hooks/test
## explicit; go 1.13
github.com/stretchr/testify/assert
github.com/stretchr/testify/require
# github.com/stripe/goproxy v0.0.0-20230801191332-fabc3ecb7251
# github.com/stripe/goproxy v0.0.0-20220308202309-3f1dfba6d1a4
## explicit; go 1.13
github.com/stripe/goproxy
# golang.org/x/mod v0.8.0
Expand Down

0 comments on commit 394167f

Please sign in to comment.