Files
gluetun/internal/httpproxy/accept.go
Quentin McGaw 84944a87d3 HTTP proxy authentication fixes (#300)
- Only accepts HTTP 1.x protocols
- Only checks the credentials when the method is `CONNECT` or the request URL is absolute
- More logging on authorization failures
- Removes the authorization headers before forwarding the HTTP(s) requests
- Refers to #298
2020-12-01 22:29:31 -05:00

25 lines
748 B
Go

package httpproxy
import (
"fmt"
"net/http"
)
func (h *handler) isAccepted(responseWriter http.ResponseWriter, request *http.Request) bool {
// Not compatible with HTTP < 1.0 or HTTP >= 2.0 (see https://github.com/golang/go/issues/14797#issuecomment-196103814)
const (
minimalMajorVersion = 1
minimalMinorVersion = 0
maximumMajorVersion = 2
maximumMinorVersion = 0
)
if !request.ProtoAtLeast(minimalMajorVersion, minimalMinorVersion) ||
request.ProtoAtLeast(maximumMajorVersion, maximumMinorVersion) {
message := fmt.Sprintf("http version not supported: %s", request.Proto)
h.logger.Info("%s, from %s", message, request.RemoteAddr)
http.Error(responseWriter, message, http.StatusBadRequest)
return false
}
return true
}