looks fine to me
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"local/rproxy3/config"
|
||||
"local/rproxy3/storage"
|
||||
@@ -8,6 +9,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const nsRouting = "routing"
|
||||
@@ -65,10 +67,11 @@ func (s *Server) doAuth(foo http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
rusr, rpwd, ok := config.GetAuth()
|
||||
if ok {
|
||||
//usr, pwd := getProxyAuth(r)
|
||||
usr, pwd, ok := r.BasicAuth()
|
||||
if !ok || rusr != usr || rpwd != pwd {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
log.Printf("denying basic auth")
|
||||
log.Printf("denying proxy basic auth")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -83,3 +86,15 @@ func (s *Server) Pre(foo http.HandlerFunc) http.HandlerFunc {
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.Pre(s.Proxy)(w, r)
|
||||
}
|
||||
|
||||
func getProxyAuth(r *http.Request) (string, string) {
|
||||
proxyAuthHeader := r.Header.Get("Proxy-Authorization")
|
||||
proxyAuthB64 := strings.TrimPrefix(proxyAuthHeader, "Basic ")
|
||||
proxyAuthBytes, _ := base64.StdEncoding.DecodeString(proxyAuthB64)
|
||||
proxyAuth := string(proxyAuthBytes)
|
||||
if !strings.Contains(proxyAuth, ":") {
|
||||
return "", ""
|
||||
}
|
||||
proxyAuthSplit := strings.Split(proxyAuth, ":")
|
||||
return proxyAuthSplit[0], proxyAuthSplit[1]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user