Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix(kernel): body size calculation in web relay (#5141)

Soumya Makkara1079ee61a17
diff --git a/packages/hoppscotch-kernel/src/relay/impl/web/v/1.ts b/packages/hoppscotch-kernel/src/relay/impl/web/v/1.ts
index ce2417b58..f72444946 100644
--- a/packages/hoppscotch-kernel/src/relay/impl/web/v/1.ts
+++ b/packages/hoppscotch-kernel/src/relay/impl/web/v/1.ts
@@ -222,6 +222,11 @@ export const implementation: VersionedAPI<RelayV1> = {
normalizedHeaders["Content-Type"] ||
normalizedHeaders["CONTENT-TYPE"]
+ const rawBody = axiosResponse.data
+ const bodySize = rawBody.byteLength
+
+ const headerSize = JSON.stringify(axiosResponse.headers).length
+
const response: RelayResponse = {
id: request.id,
status: axiosResponse.status,
@@ -235,11 +240,9 @@ export const implementation: VersionedAPI<RelayV1> = {
end: endTime,
},
size: {
- headers: JSON.stringify(axiosResponse.headers).length,
- body: axiosResponse.data?.length ?? 0,
- total:
- JSON.stringify(axiosResponse.headers).length +
- (axiosResponse.data?.length ?? 0),
+ headers: headerSize,
+ body: bodySize,
+ total: headerSize + bodySize,
},
},
}