checkPartialContentResponse if the response is a partial content response, we check if it contains the entire image.
(res *http.Response)
| 120 | // checkPartialContentResponse if the response is a partial content response, |
| 121 | // we check if it contains the entire image. |
| 122 | func 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 |
| 150 | func extractErraticBody(res *http.Response) string { |
no test coverage detected