MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / limitResponseSize

Function limitResponseSize

imagedata/response_limit.go:35–50  ·  view source on GitHub ↗

limitResponseSize limits the size of the response body to MaxSrcFileSize (if set). First, it tries to use Content-Length header to check the limit. If Content-Length is not set, it limits the size of the response body by wrapping body reader with hard limit reader.

(r *http.Response, limit int)

Source from the content-addressed store, hash-verified

33// If Content-Length is not set, it limits the size of the response body by wrapping
34// body reader with hard limit reader.
35func limitResponseSize(r *http.Response, limit int) (*http.Response, error) {
36 if limit == 0 {
37 return r, nil
38 }
39
40 // If Content-Length was set, limit the size of the response body before reading it
41 size := int(r.ContentLength)
42 if size > limit {
43 return nil, newFileSizeError()
44 }
45
46 // hard-limit the response body reader
47 r.Body = &hardLimitReadCloser{r: r.Body, left: limit}
48
49 return r, nil
50}

Callers 1

sendRequestMethod · 0.85

Calls 1

newFileSizeErrorFunction · 0.85

Tested by

no test coverage detected