Add outgoing payload size to flipper network plugin

Summary:
Flipper network plugin does not show request payload size at all, only the response.

I was trying to use flipper to check the compression ratio and overall analytics log size, but wasn't able to it, so fixed the network plugin

Reviewed By: lblasa

Differential Revision: D34062808

fbshipit-source-id: f4d4395eece9d41380b8ac6f834a014315c5db66
This commit is contained in:
Erkka Marjakangas
2022-02-14 10:20:33 -08:00
committed by Facebook GitHub Bot
parent 4e766c44bd
commit c973f4eba0
3 changed files with 28 additions and 6 deletions

View File

@@ -197,14 +197,26 @@ function escapedString(str: string) {
return "'" + str + "'";
}
export function getResponseLength(request: ResponseInfo): number {
const lengthString = request.headers
? getHeaderValue(request.headers, 'content-length')
export function getResponseLength(response: ResponseInfo): number {
const lengthString = response.headers
? getHeaderValue(response.headers, 'content-length')
: undefined;
if (lengthString) {
return parseInt(lengthString, 10);
} else if (request.data) {
return Buffer.byteLength(request.data, 'base64');
} else if (response.data) {
return Buffer.byteLength(response.data, 'base64');
}
return 0;
}
export function getRequestLength(request: Request): number {
const lengthString = request.requestHeaders
? getHeaderValue(request.requestHeaders, 'content-length')
: undefined;
if (lengthString) {
return parseInt(lengthString, 10);
} else if (request.requestData) {
return Buffer.byteLength(request.requestData, 'base64');
}
return 0;
}