newRequest creates a request with the authentication header, and with the appropriate scheme and port in the case of self-signed TLS.
(ctx context.Context, method, url string, body ...io.Reader)
| 1194 | // newRequest creates a request with the authentication header, and with the |
| 1195 | // appropriate scheme and port in the case of self-signed TLS. |
| 1196 | func (c *Client) newRequest(ctx context.Context, method, url string, body ...io.Reader) *http.Request { |
| 1197 | var bodyR io.Reader |
| 1198 | if len(body) > 0 { |
| 1199 | bodyR = body[0] |
| 1200 | } |
| 1201 | if len(body) > 1 { |
| 1202 | panic("too many body arguments") |
| 1203 | } |
| 1204 | req, err := http.NewRequest(method, url, bodyR) |
| 1205 | if err != nil { |
| 1206 | panic(err.Error()) |
| 1207 | } |
| 1208 | // not done by http.NewRequest in Go 1.0: |
| 1209 | if br, ok := bodyR.(*bytes.Reader); ok { |
| 1210 | req.ContentLength = int64(br.Len()) |
| 1211 | } |
| 1212 | c.authMode.AddAuthHeader(req) |
| 1213 | return req.WithContext(ctx) |
| 1214 | } |
| 1215 | |
| 1216 | // expect2XX will doReqGated and promote HTTP response codes outside of |
| 1217 | // the 200-299 range to a non-nil error containing the response body. |
no test coverage detected