github.com/vvnotw/moby@v1.13.1/pkg/plugins/transport/http.go (about)

     1  package transport
     2  
     3  import (
     4  	"io"
     5  	"net/http"
     6  )
     7  
     8  // httpTransport holds an http.RoundTripper
     9  // and information about the scheme and address the transport
    10  // sends request to.
    11  type httpTransport struct {
    12  	http.RoundTripper
    13  	scheme string
    14  	addr   string
    15  }
    16  
    17  // NewHTTPTransport creates a new httpTransport.
    18  func NewHTTPTransport(r http.RoundTripper, scheme, addr string) Transport {
    19  	return httpTransport{
    20  		RoundTripper: r,
    21  		scheme:       scheme,
    22  		addr:         addr,
    23  	}
    24  }
    25  
    26  // NewRequest creates a new http.Request and sets the URL
    27  // scheme and address with the transport's fields.
    28  func (t httpTransport) NewRequest(path string, data io.Reader) (*http.Request, error) {
    29  	req, err := newHTTPRequest(path, data)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  	req.URL.Scheme = t.scheme
    34  	req.URL.Host = t.addr
    35  	return req, nil
    36  }