// NewProxy returns a httputil.ReverseProxy for a request. This proxy should be used for subsequent requests of the same session.
NewProxy returns a httputil.ReverseProxy for a request. This proxy should be used for subsequent requests of the same session.
// NewProxy returns a httputil . ReverseProxy for a request . This proxy should be used for subsequent requests of the same session .
func NewProxy(req *http.Request, opts *ProxyOpts) (*httputil.ReverseProxy, error) {
	proxy := httputil.NewSingleHostReverseProxy(opts.Upstream)
	t, err := transport.New(
		opts.Registry,
		opts.Auth,
		opts.Transport,
		[]string{GetScope(req, opts.Upstream.Path)},
	)
	if err != nil {
		return nil, err
	}
	proxy.Transport = t
	proxy.Director = func(req *http.Request) {
		req.URL.Host = opts.Upstream.Host
		req.URL.Scheme = opts.Upstream.Scheme
		req.Header.Set("X-Forwarded-Host", req.Header.Get("Host"))
		req.Host = opts.Upstream.Host
		if opts.Upstream.Path != "" {
			pwb := GetPathWithBase(req.URL.Path, opts.Upstream.Path)
			req.URL.Path = pwb
		}
	}
	proxy.ModifyResponse = func(res *http.Response) error {
		originalPath, _ := res.Request.Context().Value(CtxPath).(string)
		fmt.Printf("%s: %d\n", originalPath, res.StatusCode)
		return nil
	}
	return proxy, nil
}
func NewProxy ( req * http . Request , opts * ProxyOpts ) ( * httputil . ReverseProxy , error ) { proxy := httputil . NewSingleHostReverseProxy ( opts . Upstream ) t , err := transport . New ( opts . Registry , opts . Auth , opts . Transport , [ ] string { GetScope ( req , opts . Upstream . Path ) } , ) if err != nil { return nil , err } proxy . Transport = t proxy . Director = func ( req * http . Request ) { req . URL . Host = opts . Upstream . Host req . URL . Scheme = opts . Upstream . Scheme req . Header . Set ( " " , req . Header . Get ( " " ) ) req . Host = opts . Upstream . Host if opts . Upstream . Path != " " { pwb := GetPathWithBase ( req . URL . Path , opts . Upstream . Path ) req . URL . Path = pwb } } proxy . ModifyResponse = func ( res * http . Response ) error { originalPath , _ := res . Request . Context ( ) . Value ( CtxPath ) . ( string ) fmt . Printf ( " \n " , originalPath , res . StatusCode ) return nil } return proxy , nil }
NewProxy returns a httputil.ReverseProxy for a request.
NewProxy returns a httputil . ReverseProxy for a request .
// Create docker registry transport // Support TLS upstream from HTTP connections