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

@@ -49,6 +49,7 @@ import {
convertRequestToCurlCommand, convertRequestToCurlCommand,
getHeaderValue, getHeaderValue,
getResponseLength, getResponseLength,
getRequestLength,
formatStatus, formatStatus,
formatBytes, formatBytes,
formatDuration, formatDuration,
@@ -553,6 +554,7 @@ function updateRequestWithResponseInfo(
responseData: decodeBody(response.headers, response.data), responseData: decodeBody(response.headers, response.data),
responseIsMock: response.isMock, responseIsMock: response.isMock,
responseLength: getResponseLength(response), responseLength: getResponseLength(response),
requestLength: getRequestLength(request),
duration: response.timestamp - request.requestTime.getTime(), duration: response.timestamp - request.requestTime.getTime(),
insights: response.insights ?? undefined, insights: response.insights ?? undefined,
}; };
@@ -675,9 +677,16 @@ const baseColumns: DataTableColumn<Request>[] = [
formatters: formatStatus, formatters: formatStatus,
align: 'right', align: 'right',
}, },
{
key: 'requestLength',
title: 'Request Size',
width: 100,
formatters: formatBytes,
align: 'right',
},
{ {
key: 'responseLength', key: 'responseLength',
title: 'Size', title: 'Response Size',
width: 100, width: 100,
formatters: formatBytes, formatters: formatBytes,
align: 'right', align: 'right',

View File

@@ -28,6 +28,7 @@ export interface Request {
responseHeaders?: Array<Header>; responseHeaders?: Array<Header>;
responseData?: string | Uint8Array | undefined; responseData?: string | Uint8Array | undefined;
responseLength?: number; responseLength?: number;
requestLength?: number;
responseIsMock?: boolean; responseIsMock?: boolean;
duration?: number; duration?: number;
insights?: Insights; insights?: Insights;

View File

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