fix basic auth

This commit is contained in:
bel
2026-09-07 22:01:26 -06:00
parent e4acfff5a2
commit 35b2a887f3
2 changed files with 20 additions and 6 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ type (
Endpoint struct {
To string
Redir bool
BasicAuth string
BasicAuth string `yaml:"basicAuth"`
}
)
+16 -2
View File
@@ -47,13 +47,27 @@ func (c Config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if endpoint.Redir {
c.serveHTTPRedir(w, r, endpoint)
} else {
c.serveHTTPProxy(w, r, endpoint)
}
}
func (c Config) serveHTTPRedir(w http.ResponseWriter, r *http.Request, endpoint Endpoint) {
if !c.basicAuth(w, r) {
return
}
u, _ := url.Parse(endpoint.To)
r.URL = u
r.Host = u.Host
http.Redirect(w, r, r.URL.String(), http.StatusSeeOther)
return
}
}
var someDialer = &net.Dialer{}
func (c Config) serveHTTPProxy(w http.ResponseWriter, r *http.Request, endpoint Endpoint) {
cors(w)
if r.Method == http.MethodOptions {
w.Header().Set("Content-Length", "0")
@@ -86,7 +100,7 @@ func (c Config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if idx := strings.LastIndex(u.Host, ":"); idx > 0 {
ip = ip + u.Host[idx:]
}
return (&net.Dialer{}).DialContext(ctx, network, ip)
return someDialer.DialContext(ctx, network, ip)
}
}