Skip to content

Commit

Permalink
http_proxy(error): make error messages to be lower case
Browse files Browse the repository at this point in the history
  • Loading branch information
Choraden committed Nov 7, 2023
1 parent e81fdb6 commit f30c1c4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions http_proxy_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"net"
"net/http"
"strings"

"github.com/saucelabs/forwarder/internal/martian/proxyutil"
)
Expand Down Expand Up @@ -50,7 +51,7 @@ func (hp *HTTPProxy) errorResponse(req *http.Request, err error) *http.Response
}
if code == 0 {
code = http.StatusInternalServerError
msg = "An unexpected error occurred"
msg = "an unexpected error occurred"
label = "unexpected_error"
}

Expand Down Expand Up @@ -78,10 +79,10 @@ func handleNetError(_ *http.Request, err error) (code int, msg, label string) {
if errors.As(err, &netErr) {
if netErr.Timeout() {
code = http.StatusGatewayTimeout
msg = "Timed out connecting to remote host"
msg = "timed out connecting to remote host"
} else {
code = http.StatusBadGateway
msg = "Failed to connect to remote host"
msg = "failed to connect to remote host"
}
label = "net_" + netErr.Op
}
Expand All @@ -93,7 +94,7 @@ func handleTLSRecordHeader(_ *http.Request, err error) (code int, msg, label str
var headerErr *tls.RecordHeaderError
if errors.As(err, &headerErr) {
code = http.StatusBadGateway
msg = "TLS handshake failed"
msg = "tls handshake failed"
label = "tls_record_header"
}

Expand All @@ -104,7 +105,7 @@ func handleTLSCertificateError(_ *http.Request, err error) (code int, msg, label
var certErr *tls.CertificateVerificationError
if errors.As(err, &certErr) {
code = http.StatusBadGateway
msg = "TLS handshake failed"
msg = "tls handshake failed"
label = "tls_certificate"
}

Expand All @@ -129,7 +130,7 @@ func handleStatusText(req *http.Request, err error) (code int, msg, label string
if req.URL.Scheme == "https" && err != nil {
for i := 400; i < 600; i++ {
if err.Error() == http.StatusText(i) {
return i, err.Error(), "https_status_text"
return i, strings.ToLower(err.Error()), "https_status_text"
}
}
}
Expand Down

0 comments on commit f30c1c4

Please sign in to comment.