// ProxyHandler returns a http.HandlerFunc
ProxyHandler returns a http.HandlerFunc
// ProxyHandler returns a http . HandlerFunc
func ProxyHandler(opts *ProxyOpts) func(http.ResponseWriter, *http.Request) {
	return func(res http.ResponseWriter, req *http.Request) {
		fmt.Printf("received request: %#v\n", req)
		if req.URL.Path == "/_/v1/auth" {
			Authenticate(opts, res, req)
			return
		}
		reqAuth := GetAuthentication(req)
		if reqAuth == nil {
			UnauthenticatedResponse(res, req, opts.Upstream.Path)
			return
		}
		if req.URL.Path == "/v2/" {
			res.WriteHeader(http.StatusOK)
			return
		}
		repository := GetRepositoryFromPath(req.URL.Path)
		if repository != reqAuth.DockerRepository {
			UnauthenticatedResponse(res, req, opts.Upstream.Path)
			return
		}
		proxy, err := NewProxy(req, opts)
		if err != nil {
			logger.Warn("could not create proxy", zap.Error(err))
			res.WriteHeader(http.StatusBadRequest)
			return
		}
		newCtx := context.WithValue(req.Context(), CtxPath, req.URL.Path)
		req = req.WithContext(newCtx)
		proxy.ServeHTTP(res, req)
	}
}
func ProxyHandler ( opts * ProxyOpts ) func ( http . ResponseWriter , * http . Request ) { return func ( res http . ResponseWriter , req * http . Request ) { fmt . Printf ( " \n " , req ) if req . URL . Path == " " { Authenticate ( opts , res , req ) return } reqAuth := GetAuthentication ( req ) if reqAuth == nil { UnauthenticatedResponse ( res , req , opts . Upstream . Path ) return } if req . URL . Path == " " { res . WriteHeader ( http . StatusOK ) return } repository := GetRepositoryFromPath ( req . URL . Path ) if repository != reqAuth . DockerRepository { UnauthenticatedResponse ( res , req , opts . Upstream . Path ) return } proxy , err := NewProxy ( req , opts ) if err != nil { logger . Warn ( " " , zap . Error ( err ) ) res . WriteHeader ( http . StatusBadRequest ) return } newCtx := context . WithValue ( req . Context ( ) , CtxPath , req . URL . Path ) req = req . WithContext ( newCtx ) proxy . ServeHTTP ( res , req ) } }
ProxyHandler returns a http.HandlerFunc
ProxyHandler returns a http . HandlerFunc
// TODO: maybe use forbidden instead? check API docs // add original path to request context