DoRequest sends a request that the caller has already built, and returns the response for the caller to consume. It applies the same error handling as Request. Prefer Request. DoRequest exists for the few call sites that must control something Request cannot express. That is either a field of the r
(req *http.Request, opts ...RequestOption)
| 260 | // Responses outside the 2xx range are returned as an HTTPError and their body is closed. On success |
| 261 | // the response is returned unread and the caller is responsible for closing its body. |
| 262 | func (c Client) DoRequest(req *http.Request, opts ...RequestOption) (*http.Response, error) { |
| 263 | cfg := newRequestConfig(opts) |
| 264 | |
| 265 | resp, err := c.http.Do(req) |
| 266 | if err != nil { |
| 267 | return nil, err |
| 268 | } |
| 269 | |
| 270 | success := resp.StatusCode >= 200 && resp.StatusCode < 300 |
| 271 | if !success { |
| 272 | defer resp.Body.Close() |
| 273 | if cfg.endpointScopes != "" { |
| 274 | EndpointNeedsScopes(resp, cfg.endpointScopes) |
| 275 | } |
| 276 | return nil, HandleHTTPError(resp) |
| 277 | } |
| 278 | |
| 279 | return resp, nil |
| 280 | } |
| 281 | |
| 282 | // HandleHTTPError parses a http.Response into a HTTPError. |
| 283 | // |