correctly handle gzipped unicode fixes 394
Summary: For gzipped requests, the decoding of unicode characters was failing, because it was was done, before decompressing the response payload. In this diff, the payload is first decompressed and decoded afterwards. For the calculation of the response size, this is removed, because it doesn't matter for the calculation of the size to correctly decode unicode characters. However, there might be a problem with displaying the correct size. This is tracked in T41427687. Reviewed By: jknoxville Differential Revision: D14366841 fbshipit-source-id: e375df1ec44505f6315dedbe71b3b62eac0f281a
This commit is contained in:
committed by
Facebook Github Bot
parent
83c9d3399f
commit
2c05fdf347
@@ -62,11 +62,15 @@ function decodeBody(container: Request | Response): string {
|
||||
if (!container.data) {
|
||||
return '';
|
||||
}
|
||||
const b64Decoded = decodeURIComponent(escape(atob(container.data)));
|
||||
const b64Decoded = atob(container.data);
|
||||
const body =
|
||||
getHeaderValue(container.headers, 'Content-Encoding') === 'gzip'
|
||||
? decompress(b64Decoded)
|
||||
: b64Decoded;
|
||||
|
||||
return getHeaderValue(container.headers, 'Content-Encoding') === 'gzip'
|
||||
? decompress(b64Decoded)
|
||||
: b64Decoded;
|
||||
// Data is transferred as base64 encoded bytes to support unicode characters,
|
||||
// we need to decode the bytes here to display the correct unicode characters.
|
||||
return decodeURIComponent(escape(body));
|
||||
}
|
||||
|
||||
function decompress(body: string): string {
|
||||
|
||||
@@ -490,7 +490,10 @@ class SizeColumn extends PureComponent<{
|
||||
if (lengthString != null && lengthString != '') {
|
||||
length = parseInt(lengthString, 10);
|
||||
} else if (response.data) {
|
||||
length = decodeURIComponent(escape(atob(response.data))).length;
|
||||
// FIXME: T41427687 This is probably not the correct way to determine
|
||||
// the correct byte size of the response, because String.length returns
|
||||
// the number of characters, not bytes.
|
||||
length = atob(response.data).length;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user