Ignore header case to determine if content is gzipped (#143)

Summary:
This PR updates the Network plugin's response parser to ignore the case of the `Content-Encoding` header in the response. This was preventing responses that are gzipped from being uncompressed. I tested this with gzipped responses through the OkHttp interceptor on Android. This could potentially address #79 as I was experiencing that issue before this change.

![sonar](https://user-images.githubusercontent.com/1328587/42414919-284b80bc-8238-11e8-8cf9-d9e9b9bea133.jpg)
Pull Request resolved: https://github.com/facebook/Sonar/pull/143

Differential Revision: D8780509

Pulled By: danielbuechele

fbshipit-source-id: 1a2d86226a8a0204ff43eb5f9394a56c04fd2d8d
This commit is contained in:
Arvind Menon
2018-07-10 06:07:39 -07:00
committed by Facebook Github Bot
parent dad05de943
commit c8c2cfa16f
2 changed files with 2 additions and 5 deletions

View File

@@ -56,11 +56,8 @@ function decodeBody(container: Request | Response): string {
return '';
}
const b64Decoded = atob(container.data);
const encodingHeader = container.headers.find(
header => header.key === 'Content-Encoding',
);
return encodingHeader && encodingHeader.value === 'gzip'
return getHeaderValue(container.headers, 'Content-Encoding') === 'gzip'
? decompress(b64Decoded)
: b64Decoded;
}

View File

@@ -81,7 +81,7 @@ const COLUMNS = {
},
};
export function getHeaderValue(headers: Array<Header>, key: string) {
export function getHeaderValue(headers: Array<Header>, key: string): string {
for (const header of headers) {
if (header.key.toLowerCase() === key.toLowerCase()) {
return header.value;