Skip to content

Commit a1079ee

Browse files
fix(kernel): body size calculation in web relay (hoppscotch#5141)
Co-authored-by: CuriousCorrelation <[email protected]>
1 parent 8a88016 commit a1079ee

File tree

1 file changed

+8
-5
lines changed
  • packages/hoppscotch-kernel/src/relay/impl/web/v

1 file changed

+8
-5
lines changed

packages/hoppscotch-kernel/src/relay/impl/web/v/1.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ export const implementation: VersionedAPI<RelayV1> = {
222222
normalizedHeaders["Content-Type"] ||
223223
normalizedHeaders["CONTENT-TYPE"]
224224

225+
const rawBody = axiosResponse.data
226+
const bodySize = rawBody.byteLength
227+
228+
const headerSize = JSON.stringify(axiosResponse.headers).length
229+
225230
const response: RelayResponse = {
226231
id: request.id,
227232
status: axiosResponse.status,
@@ -235,11 +240,9 @@ export const implementation: VersionedAPI<RelayV1> = {
235240
end: endTime,
236241
},
237242
size: {
238-
headers: JSON.stringify(axiosResponse.headers).length,
239-
body: axiosResponse.data?.length ?? 0,
240-
total:
241-
JSON.stringify(axiosResponse.headers).length +
242-
(axiosResponse.data?.length ?? 0),
243+
headers: headerSize,
244+
body: bodySize,
245+
total: headerSize + bodySize,
243246
},
244247
},
245248
}

0 commit comments

Comments
 (0)