From 568c005d15aeca9f934315e9c2d3a9557298364e Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Fri, 10 Feb 2023 12:44:01 +0100 Subject: [PATCH] httpx: Remove unuused methods --- pkg/httpx/basic.go | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 pkg/httpx/basic.go diff --git a/pkg/httpx/basic.go b/pkg/httpx/basic.go deleted file mode 100644 index 65d5404..0000000 --- a/pkg/httpx/basic.go +++ /dev/null @@ -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) - }) -}