Skip to content

Commit 33be076

Browse files
committed
fix: send 407 before last return
1 parent 6500f0a commit 33be076

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

auth/common.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"net"
88
"net/http"
9-
"strconv"
109
"strings"
1110

1211
clog "github.com/SenseUnit/dumbproxy/log"
@@ -25,10 +24,8 @@ func requireBasicAuth(ctx context.Context, wr http.ResponseWriter, req *http.Req
2524
if hidden_domain != "" {
2625
if matchHiddenDomain(req.URL.Host, hidden_domain) ||
2726
matchHiddenDomain(req.Host, hidden_domain) {
28-
wr.Header().Set("Proxy-Authenticate", `Basic realm="dumbproxy"`)
29-
wr.Header().Set("Content-Length", strconv.Itoa(len([]byte(AUTH_REQUIRED_MSG))))
30-
wr.WriteHeader(http.StatusProxyAuthRequired)
31-
wr.Write([]byte(AUTH_REQUIRED_MSG))
27+
wr.Header().Set("Proxy-Authenticate", BASIC_REALM_MSG)
28+
http.Error(wr, AUTH_REQUIRED_MSG, http.StatusProxyAuthRequired)
3229
return "", false
3330
}
3431

@@ -43,7 +40,9 @@ func requireBasicAuth(ctx context.Context, wr http.ResponseWriter, req *http.Req
4340
if next != nil {
4441
return next.Validate(ctx, wr, req)
4542
}
46-
43+
44+
wr.Header().Set("Proxy-Authenticate", BASIC_REALM_MSG)
45+
http.Error(wr, AUTH_REQUIRED_MSG, http.StatusProxyAuthRequired)
4746
return "", false
4847
}
4948

auth/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ const AUTH_REQUIRED_MSG = "Proxy authentication required.\n"
44
const BAD_REQ_MSG = "Bad Request\n"
55
const AUTH_TRIGGERED_MSG = "Browser auth triggered!\n"
66
const EPOCH_EXPIRE = "Thu, 01 Jan 1970 00:00:01 GMT"
7+
const BASIC_REALM_MSG = `Basic realm="dumbproxy"`

0 commit comments

Comments
 (0)