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

     1  package transport
     2  
     3  import (
     4  	"io"
     5  	"net/http"
     6  	"strings"
     7  )
     8  
     9  // VersionMimetype is the Content-Type the engine sends to plugins.
    10  const VersionMimetype = "application/vnd.docker.plugins.v1.2+json"
    11  
    12  // RequestFactory defines an interface that
    13  // transports can implement to create new requests.
    14  type RequestFactory interface {
    15  	NewRequest(path string, data io.Reader) (*http.Request, error)
    16  }
    17  
    18  // Transport defines an interface that plugin transports
    19  // must implement.
    20  type Transport interface {
    21  	http.RoundTripper
    22  	RequestFactory
    23  }
    24  
    25  // newHTTPRequest creates a new request with a path and a body.
    26  func newHTTPRequest(path string, data io.Reader) (*http.Request, error) {
    27  	if !strings.HasPrefix(path, "/") {
    28  		path = "/" + path
    29  	}
    30  	req, err := http.NewRequest("POST", path, data)
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  	req.Header.Add("Accept", VersionMimetype)
    35  	return req, nil
    36  }