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

Method negotiateCodec

pkg/api/queryapi/query_api.go:284–299  ·  view source on GitHub ↗
(req *http.Request, resp *v1.Response)

Source from the content-addressed store, hash-verified

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")) {
286 for _, codec := range q.codecs {
287 if codec.ContentType().Satisfies(clause) && codec.CanEncode(resp) {
288 return codec, nil
289 }
290 }
291 }
292
293 defaultCodec := q.codecs[0]
294 if !defaultCodec.CanEncode(resp) {
295 return nil, fmt.Errorf("cannot encode response as %s", defaultCodec.ContentType())
296 }
297
298 return defaultCodec, nil
299}

Callers 1

respondMethod · 0.95

Calls 3

GetMethod · 0.65
ContentTypeMethod · 0.65
CanEncodeMethod · 0.45

Tested by

no test coverage detected