DecompressResponse automatically decompresses response data based on Content-Encoding header
(contentEncoding string, data []byte)
| 35 | |
| 36 | // DecompressResponse automatically decompresses response data based on Content-Encoding header |
| 37 | func DecompressResponse(contentEncoding string, data []byte) ([]byte, error) { |
| 38 | // If no encoding specified or empty data, return as-is |
| 39 | if contentEncoding == "" || len(data) == 0 { |
| 40 | return data, nil |
| 41 | } |
| 42 | |
| 43 | // Look up the decompressor |
| 44 | decompressor, exists := decompressorRegistry[contentEncoding] |
| 45 | if !exists { |
| 46 | logrus.Warnf("No decompressor registered for encoding '%s', returning original data", contentEncoding) |
| 47 | return data, nil |
| 48 | } |
| 49 | |
| 50 | // Decompress |
| 51 | decompressed, err := decompressor.Decompress(data) |
| 52 | if err != nil { |
| 53 | logrus.WithError(err).Warnf("Failed to decompress with '%s', returning original data", contentEncoding) |
| 54 | return data, nil |
| 55 | } |
| 56 | |
| 57 | logrus.Debugf("Successfully decompressed %d bytes -> %d bytes using '%s'", |
| 58 | len(data), len(decompressed), contentEncoding) |
| 59 | return decompressed, nil |
| 60 | } |
| 61 | |
| 62 | // GzipDecompressor handles gzip compression |
| 63 | type GzipDecompressor struct{} |
no test coverage detected