Skip to content

Commit 5884845

Browse files
committed
fix: Prevent read bodies
If a callback reads the body of a response it essentially renders that response useless.
1 parent 1f9f636 commit 5884845

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/api/Api.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,13 @@ export class Api {
275275
Object.seal(response)
276276

277277
for (const callback of callbacks) {
278-
await callback(response)
278+
// note: this does not quite work as the response body
279+
// cannot be modified or even read twice.
280+
// the current solution of cloning the response
281+
// to every callback, may incur performance
282+
// pressure as typical callbacks likely want to examine the
283+
// request body and would repeatedly parse the json bodies
284+
await callback(response.clone())
279285
}
280286

281287
return response

0 commit comments

Comments
 (0)