httpx: Remove unuused methods
This commit is contained in:
parent
b1009fa109
commit
568c005d15
1 changed files with 0 additions and 24 deletions
|
|
@ -1,24 +0,0 @@
|
||||||
package httpx
|
|
||||||
|
|
||||||
import "net/http"
|
|
||||||
|
|
||||||
var basicUnauthorized = []byte("Unauthorized")
|
|
||||||
|
|
||||||
// BasicAuth returns a new [http.Handler] that requires any credentials to pass the check function
|
|
||||||
func BasicAuth(handler http.Handler, realm string, check func(username, password string) bool) http.Handler {
|
|
||||||
var authenticateHeader = `Basic realm="` + realm + `"`
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// if the basic authentication passes
|
|
||||||
// we can just use the handler!
|
|
||||||
user, pass, ok := r.BasicAuth()
|
|
||||||
if ok && check(user, pass) {
|
|
||||||
handler.ServeHTTP(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// http authentication did not pass
|
|
||||||
w.Header().Add("WWW-Authenticate", authenticateHeader)
|
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
|
||||||
w.Write(basicUnauthorized)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue