MCPcopy Index your code
hub / github.com/cortexproject/cortex / respond

Method respond

pkg/api/queryapi/query_api.go:253–282  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request, data any, warnings annotations.Annotations, query string)

Source from the content-addressed store, hash-verified

251}
252
253func (q *QueryAPI) respond(w http.ResponseWriter, req *http.Request, data any, warnings annotations.Annotations, query string) {
254 warn, info := warnings.AsStrings(query, 10, 10)
255
256 resp := &v1.Response{
257 Status: statusSuccess,
258 Data: data,
259 Warnings: warn,
260 Infos: info,
261 }
262
263 codec, err := q.negotiateCodec(req, resp)
264 if err != nil {
265 api.RespondFromGRPCError(q.logger, w, httpgrpc.Errorf(http.StatusNotAcceptable, "%s", &apiError{errorNotAcceptable, err}))
266 return
267 }
268
269 b, err := codec.Encode(resp)
270 if err != nil {
271 level.Error(q.logger).Log("error marshaling response", "url", req.URL, "err", err)
272 http.Error(w, err.Error(), http.StatusInternalServerError)
273 return
274 }
275
276 w.Header().Set("Content-Type", codec.ContentType().String())
277 w.Header().Set("X-Uncompressed-Length", strconv.Itoa(len(b)))
278 w.WriteHeader(http.StatusOK)
279 if n, err := w.Write(b); err != nil {
280 level.Error(q.logger).Log("error writing response", "url", req.URL, "bytesWritten", n, "err", err)
281 }
282}
283
284func (q *QueryAPI) negotiateCodec(req *http.Request, resp *v1.Response) (v1.Codec, error) {
285 for _, clause := range goautoneg.ParseAccept(req.Header.Get("Accept")) {

Callers 1

WrapMethod · 0.95

Calls 10

negotiateCodecMethod · 0.95
RespondFromGRPCErrorFunction · 0.92
EncodeMethod · 0.65
SetMethod · 0.65
StringMethod · 0.65
ContentTypeMethod · 0.65
LogMethod · 0.45
ErrorMethod · 0.45
HeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected