Skip to content

Commit

Permalink
http_proxy: make errorResponse func a proxy method
Browse files Browse the repository at this point in the history
  • Loading branch information
Choraden authored and mmatczuk committed Oct 17, 2023
1 parent a9e5d1c commit 8088def
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion http_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
ErrProxyDenied = denyError{errors.New("proxying denied")}
)

func errorResponse(req *http.Request, err error) *http.Response {
func (hp *HTTPProxy) errorResponse(req *http.Request, err error) *http.Response {
handlers := []errorHandler{
handleNetError,
handleTLSRecordHeader,
Expand Down
6 changes: 3 additions & 3 deletions http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (hp *HTTPProxy) configureProxy() error {
hp.proxy.ConnectRequestModifier = hp.config.ConnectRequestModifier
hp.proxy.ConnectPassthrough = hp.config.ConnectPassthrough
hp.proxy.WithoutWarning = true
hp.proxy.ErrorResponse = errorResponse
hp.proxy.ErrorResponse = hp.errorResponse
hp.proxy.CloseAfterReply = hp.config.CloseAfterReply
hp.proxy.ReadTimeout = hp.config.ReadTimeout
hp.proxy.ReadHeaderTimeout = hp.config.ReadHeaderTimeout
Expand Down Expand Up @@ -450,15 +450,15 @@ func (hp *HTTPProxy) basicAuth(u *url.Userinfo) martian.RequestModifier {

func (hp *HTTPProxy) denyLocalhost() martian.RequestModifier {
return hp.abortIf(hp.isLocalhost, func(req *http.Request) *http.Response {
return errorResponse(req, ErrProxyLocalhost)
return hp.errorResponse(req, ErrProxyLocalhost)
}, errors.New("localhost access denied"))
}

func (hp *HTTPProxy) denyDomains(r *ruleset.RegexpMatcher) martian.RequestModifier {
return hp.abortIf(func(req *http.Request) bool {
return r.Match(req.URL.Hostname())
}, func(req *http.Request) *http.Response {
return errorResponse(req, ErrProxyDenied)
return hp.errorResponse(req, ErrProxyDenied)
}, errors.New("domain access denied"))
}

Expand Down

0 comments on commit 8088def

Please sign in to comment.