@@ -22,19 +22,28 @@ func matchHiddenDomain(host, hidden_domain string) bool {
2222}
2323
2424func requireBasicAuth (ctx context.Context , wr http.ResponseWriter , req * http.Request , hidden_domain string , next Auth ) (string , bool ) {
25+ if hidden_domain != "" {
26+ if matchHiddenDomain (req .URL .Host , hidden_domain ) ||
27+ 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 ))
32+ return "" , false
33+ }
34+
35+ if next != nil {
36+ return next .Validate (ctx , wr , req )
37+ }
38+
39+ http .Error (wr , BAD_REQ_MSG , http .StatusBadRequest )
40+ return "" , false
41+ }
42+
2543 if next != nil {
2644 return next .Validate (ctx , wr , req )
2745 }
28- if hidden_domain != "" &&
29- ! matchHiddenDomain (req .URL .Host , hidden_domain ) &&
30- ! matchHiddenDomain (req .Host , hidden_domain ) {
31- http .Error (wr , BAD_REQ_MSG , http .StatusBadRequest )
32- } else {
33- wr .Header ().Set ("Proxy-Authenticate" , `Basic realm="dumbproxy"` )
34- wr .Header ().Set ("Content-Length" , strconv .Itoa (len ([]byte (AUTH_REQUIRED_MSG ))))
35- wr .WriteHeader (407 )
36- wr .Write ([]byte (AUTH_REQUIRED_MSG ))
37- }
46+
3847 return "" , false
3948}
4049
0 commit comments