Files
mjq2020 23181baaa8 fix(network): report UTF-8 response byte size (#783)
## Summary

- measure React Native response bodies from a cloned Blob instead of a
decoded JavaScript string
- report one consistent metric: decoded response entity bytes
- avoid Content-Length because HEAD/304 and compressed responses give it
different semantics
- keep response text capture independent, and leave the size unknown if
Blob conversion is unavailable

## Root cause

body.length counts UTF-16 code units. Re-encoding the decoded text as
UTF-8 fixes ordinary UTF-8 text, but it overcounts replacement
characters from non-UTF-8 and binary responses. Content-Length is also
not a safe fallback: it can describe an unsent GET body for HEAD/304 or
the compressed wire representation while the response body is
decompressed.

Response.blob().size measures the bytes in the decoded entity supplied
by the React Native response. The same measurement therefore applies to
text, binary, empty, cached, and compressed responses.

## Tests

- network interceptor regression: 23/23 passed
- covers Unicode JSON, HEAD, 304, non-UTF-8 replacement characters,
compression, binary bodies, and unavailable Blob conversion
- npm run build
- npm run typecheck:tests -w @argent/tool-server
- targeted ESLint and Prettier checks on both changed files

Fixes #662

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved reported network response sizes to reflect the actual decoded
response data.
- Corrected size calculations for binary content, compressed responses,
and text containing non-ASCII characters.
- Added reliable handling for `HEAD` and `304` responses, which now
report zero size.
- Prevented failed size calculations from incorrectly reporting a
zero-byte response.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-02 10:32:58 +02:00
..