MCPcopy
hub / github.com/dnote/dnote / doReq

Function doReq

pkg/cli/client/client.go:170–195  ·  view source on GitHub ↗

doReq does a http request to the given path in the api endpoint

(ctx context.DnoteCtx, method, path, body string, options *requestOptions)

Source from the content-addressed store, hash-verified

168
169// doReq does a http request to the given path in the api endpoint
170func 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.

Callers 3

doAuthorizedReqFunction · 0.85
GetPresigninFunction · 0.85
SigninFunction · 0.85

Calls 5

DebugFunction · 0.92
getReqFunction · 0.85
getHTTPClientFunction · 0.85
checkRespErrFunction · 0.85
checkContentTypeFunction · 0.85

Tested by

no test coverage detected