MCPcopy Create free account
hub / github.com/cortexproject/cortex / BodyBytes

Function BodyBytes

pkg/querier/tripperware/query.go:448–469  ·  view source on GitHub ↗
(res *http.Response, logger log.Logger)

Source from the content-addressed store, hash-verified

446}
447
448func BodyBytes(res *http.Response, logger log.Logger) ([]byte, error) {
449 var buf *bytes.Buffer
450
451 // Attempt to cast the response body to a Buffer and use it if possible.
452 // This is because the frontend may have already read the body and buffered it.
453 if buffer, ok := res.Body.(Buffer); ok {
454 buf = bytes.NewBuffer(buffer.Bytes())
455 } else {
456 // Preallocate the buffer with the exact size so we don't waste allocations
457 // while progressively growing an initial small buffer. The buffer capacity
458 // is increased by MinRead to avoid extra allocations due to how ReadFrom()
459 // internally works.
460 buf = bytes.NewBuffer(make([]byte, 0, res.ContentLength+bytes.MinRead))
461 if _, err := buf.ReadFrom(res.Body); err != nil {
462 return nil, httpgrpc.Errorf(http.StatusInternalServerError, "error decoding response: %v", err)
463 }
464 }
465
466 // Handle decoding response if it was compressed
467 encoding := res.Header.Get("Content-Encoding")
468 return decode(buf, encoding, logger)
469}
470
471func BodyBytesFromHTTPGRPCResponse(res *httpgrpc.HTTPResponse, logger log.Logger) ([]byte, error) {
472 headers := http.Header{}

Callers 3

ServeHTTPMethod · 0.92
DecodeResponseMethod · 0.92
DecodeResponseMethod · 0.92

Calls 3

decodeFunction · 0.85
BytesMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected