processContentEncoding performs the Content-Type validation and Content-Encoding check.
(headers http.Header, input io.ReadCloser, expectedContentTypeMime string)
| 69 | |
| 70 | // processContentEncoding performs the Content-Type validation and Content-Encoding check. |
| 71 | func processContentEncoding(headers http.Header, input io.ReadCloser, expectedContentTypeMime string) (io.ReadCloser, error) { |
| 72 | contentType := headers.Get("Content-Type") |
| 73 | if contentType != "" && !strings.HasPrefix(contentType, expectedContentTypeMime) { |
| 74 | return input, base.HTTPErrorf(http.StatusUnsupportedMediaType, "Invalid content type %s - expected %s", contentType, expectedContentTypeMime) |
| 75 | } |
| 76 | switch headers.Get("Content-Encoding") { |
| 77 | case "gzip": |
| 78 | var err error |
| 79 | if input, err = gzip.NewReader(input); err != nil { |
| 80 | return input, err |
| 81 | } |
| 82 | case "": |
| 83 | break |
| 84 | default: |
| 85 | return input, base.HTTPErrorf(http.StatusUnsupportedMediaType, "Unsupported Content-Encoding; use gzip") |
| 86 | } |
| 87 | return input, nil |
| 88 | } |
| 89 | |
| 90 | type attInfo struct { |
| 91 | name string |
no test coverage detected