doReq does a http request to the given path in the api endpoint
(ctx context.DnoteCtx, method, path, body string, options *requestOptions)
| 168 | |
| 169 | // doReq does a http request to the given path in the api endpoint |
| 170 | func doReq(ctx context.DnoteCtx, method, path, body string, options *requestOptions) (*http.Response, error) { |
| 171 | req, err := getReq(ctx, path, method, body) |
| 172 | if err != nil { |
| 173 | return nil, errors.Wrap(err, "getting request") |
| 174 | } |
| 175 | |
| 176 | log.Debug("HTTP %s %s\n", method, path) |
| 177 | |
| 178 | hc := getHTTPClient(ctx, options) |
| 179 | res, err := hc.Do(req) |
| 180 | if err != nil { |
| 181 | return res, errors.Wrap(err, "making http request") |
| 182 | } |
| 183 | |
| 184 | log.Debug("HTTP %d %s\n", res.StatusCode, res.Status) |
| 185 | |
| 186 | if err = checkRespErr(res); err != nil { |
| 187 | return res, errors.Wrap(err, "server responded with an error") |
| 188 | } |
| 189 | |
| 190 | if err = checkContentType(res, options); err != nil { |
| 191 | return res, errors.Wrap(err, "unexpected Content-Type") |
| 192 | } |
| 193 | |
| 194 | return res, nil |
| 195 | } |
| 196 | |
| 197 | // doAuthorizedReq does a http request to the given path in the api endpoint as a user, |
| 198 | // with the appropriate headers. The given path should include the preceding slash. |
no test coverage detected