MCPcopy
hub / github.com/minio/minio-go / NewRequest

Function NewRequest

pkg/signer/test-utils_test.go:53–103  ·  view source on GitHub ↗

N B minio-go should compile on go1.5.3 onwards and httptest package is available only from go.1.7.x. The following function is taken from Go httptest package to be able to build on older versions of Go. NewRequest returns a new incoming server Request, suitable for passing to an http.Handler for tes

(method, target string, body io.Reader)

Source from the content-addressed store, hash-verified

51// NewRequest panics on error for ease of use in testing, where a
52// panic is acceptable.
53func NewRequest(method, target string, body io.Reader) *http.Request {
54 if method == "" {
55 method = http.MethodGet
56 }
57 req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(method + " " + target + " HTTP/1.0\r\n\r\n")))
58 if err != nil {
59 panic("invalid NewRequest arguments; " + err.Error())
60 }
61
62 // HTTP/1.0 was used above to avoid needing a Host field. Change it to 1.1 here.
63 req.Proto = "HTTP/1.1"
64 req.ProtoMinor = 1
65 req.Close = false
66
67 if body != nil {
68 switch v := body.(type) {
69 case *bytes.Buffer:
70 req.ContentLength = int64(v.Len())
71 case *bytes.Reader:
72 req.ContentLength = int64(v.Len())
73 case *strings.Reader:
74 req.ContentLength = int64(v.Len())
75 default:
76 req.ContentLength = -1
77 }
78 if rc, ok := body.(io.ReadCloser); ok {
79 req.Body = rc
80 } else {
81 req.Body = io.NopCloser(body)
82 }
83 }
84
85 // 192.0.2.0/24 is "TEST-NET" in RFC 5737 for use solely in
86 // documentation and example source code and should not be
87 // used publicly.
88 req.RemoteAddr = "192.0.2.1:1234"
89
90 if req.Host == "" {
91 req.Host = "example.com"
92 }
93
94 if strings.HasPrefix(target, "https://") {
95 req.TLS = &tls.ConnectionState{
96 Version: tls.VersionTLS12,
97 HandshakeComplete: true,
98 ServerName: req.Host,
99 }
100 }
101
102 return req
103}

Callers 4

TestGetSeedSignatureFunction · 0.85
TestStreamingReaderFunction · 0.85

Calls 2

LenMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected