From c8c2cfa16f1f73d985298a3b54220c54455f6d6d Mon Sep 17 00:00:00 2001 From: Arvind Menon Date: Tue, 10 Jul 2018 06:07:39 -0700 Subject: [PATCH] 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 --- src/plugins/network/RequestDetails.js | 5 +---- src/plugins/network/index.js | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/plugins/network/RequestDetails.js b/src/plugins/network/RequestDetails.js index 736b71d92..b952ebb7d 100644 --- a/src/plugins/network/RequestDetails.js +++ b/src/plugins/network/RequestDetails.js @@ -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; } diff --git a/src/plugins/network/index.js b/src/plugins/network/index.js index 2a957dd0e..584c41a15 100644 --- a/src/plugins/network/index.js +++ b/src/plugins/network/index.js @@ -81,7 +81,7 @@ const COLUMNS = { }, }; -export function getHeaderValue(headers: Array
, key: string) { +export function getHeaderValue(headers: Array
, key: string): string { for (const header of headers) { if (header.key.toLowerCase() === key.toLowerCase()) { return header.value;