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

Function checkPartialContentResponse

fetcher/request.go:122–147  ·  view source on GitHub ↗

checkPartialContentResponse if the response is a partial content response, we check if it contains the entire image.

(res *http.Response)

Source from the content-addressed store, hash-verified

120// checkPartialContentResponse if the response is a partial content response,
121// we check if it contains the entire image.
122func checkPartialContentResponse(res *http.Response) error {
123 contentRange := res.Header.Get(httpheaders.ContentRange)
124 rangeParts := contentRangeRe.FindStringSubmatch(contentRange)
125
126 if len(rangeParts) == 0 {
127 return newPartialResponseError("Partial response with invalid Content-Range header")
128 }
129
130 if rangeParts[1] == "*" || rangeParts[2] != "0" {
131 return newPartialResponseError("Partial response with incomplete content")
132 }
133
134 contentLengthStr := rangeParts[4]
135 if contentLengthStr == "*" {
136 contentLengthStr = res.Header.Get(httpheaders.ContentLength)
137 }
138
139 contentLength, _ := strconv.Atoi(contentLengthStr)
140 rangeEnd, _ := strconv.Atoi(rangeParts[3])
141
142 if contentLength <= 0 || rangeEnd != contentLength-1 {
143 return newPartialResponseError("Partial response with incomplete content")
144 }
145
146 return nil
147}
148
149// extractErraticBody extracts the error body from the response if it is a text-based content type
150func extractErraticBody(res *http.Response) string {

Callers 1

FetchMethod · 0.85

Calls 2

newPartialResponseErrorFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected