Browse code

pkg/plugins/transport: inline newHTTPRequest

It was only used in a single location; just inline the code

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2023/07/18 19:14:30
Showing 2 changed files
... ...
@@ -3,6 +3,7 @@ package transport // import "github.com/docker/docker/pkg/plugins/transport"
3 3
 import (
4 4
 	"io"
5 5
 	"net/http"
6
+	"strings"
6 7
 )
7 8
 
8 9
 // httpTransport holds an http.RoundTripper
... ...
@@ -26,10 +27,14 @@ func NewHTTPTransport(r http.RoundTripper, scheme, addr string) Transport {
26 26
 // NewRequest creates a new http.Request and sets the URL
27 27
 // scheme and address with the transport's fields.
28 28
 func (t httpTransport) NewRequest(path string, data io.Reader) (*http.Request, error) {
29
-	req, err := newHTTPRequest(path, data)
29
+	if !strings.HasPrefix(path, "/") {
30
+		path = "/" + path
31
+	}
32
+	req, err := http.NewRequest(http.MethodPost, path, data)
30 33
 	if err != nil {
31 34
 		return nil, err
32 35
 	}
36
+	req.Header.Add("Accept", VersionMimetype)
33 37
 	req.URL.Scheme = t.scheme
34 38
 	req.URL.Host = t.addr
35 39
 	return req, nil
... ...
@@ -3,7 +3,6 @@ package transport // import "github.com/docker/docker/pkg/plugins/transport"
3 3
 import (
4 4
 	"io"
5 5
 	"net/http"
6
-	"strings"
7 6
 )
8 7
 
9 8
 // VersionMimetype is the Content-Type the engine sends to plugins.
... ...
@@ -21,16 +20,3 @@ type Transport interface {
21 21
 	http.RoundTripper
22 22
 	RequestFactory
23 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(http.MethodPost, path, data)
31
-	if err != nil {
32
-		return nil, err
33
-	}
34
-	req.Header.Add("Accept", VersionMimetype)
35
-	return req, nil
36
-}