fix(android): cap interceptor body reads to prevent OOM on large responses#26
Merged
Conversation
Replaces `source.request(Long.MAX_VALUE)` with a bounded read so that large response bodies (images, file downloads, big JSON payloads) no longer duplicate the full payload in heap memory. - `captureResponseBody`: request `limit + 1` bytes so truncation is detectable, append `[... truncated]` marker when body exceeds cap - `captureRequestBody`: write body to a temporary buffer then read only `min(size, limit)` bytes, append truncation marker when needed - Both methods bail early with `[binary content — not captured]` for image/, video/, audio/, octet-stream, zip, pdf, and font/* types - `NetworkToolsManager.maxBodyCaptureBytes` default: 256 KB Closes #17 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Android (TurboModule + legacy bridge) and iOS now implement setMaxBodyCaptureBytes(bytes) so the capture limit can be changed at runtime from JavaScript without a rebuild. iOS: maxBodyCaptureBytes is promoted from a static compile-time constant in NetworkToolsInterceptor to a property on the NetworkToolsManager singleton, read dynamically via ntMaxBodyBytes(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Adds setMaxBodyCaptureBytes(bytes) to the TurboModule spec and the unavailable-module fallback - NetworkMonitorProviderProps gains an optional maxBodyCaptureBytes field - NetworkMonitorProvider calls the native method in a useEffect whenever the prop changes - setMaxBodyCaptureBytes is exported as a named export and on the default object for callers that bypass the provider Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
macos-latest now maps to macOS 15 which ships Ruby 3.4. kconv was removed from Ruby's stdlib in 3.4, causing CocoaPods 1.16.2 to crash during pod install with "cannot load such file -- kconv". Adds ruby/setup-ruby@v1 with ruby-version: '3.3' before the pod install step, and delegates bundle install to setup-ruby via bundler-cache: true (which also caches the gem bundle). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #17
captureResponseBody: replacessource.request(Long.MAX_VALUE)+buffer.clone().readUtf8()with a bounded read (limit + 1bytes to detect truncation without consuming it). Appends[... truncated]when the body exceeds the cap.captureRequestBody: writes body to a temporaryBuffer, then reads onlymin(size, limit)bytes. Appends truncation marker when needed.image/*,video/*,audio/*,application/octet-stream,application/zip,application/pdf,font/*) and return[binary content — not captured]instead of buffering bytes.NetworkToolsManager.maxBodyCaptureBytesdefaults to 256 KB and is publicly settable from app code.kNTMaxBodyBytescompile-time constant to amaxBodyCaptureBytesproperty onNetworkToolsManager, so it is now also configurable at runtime (iOS already had the cap logic; this makes it consistent with Android).setMaxBodyCaptureBytes(bytes)to the TurboModule spec (Android + iOS), the legacy bridge module, and the TypeScript exports.NetworkMonitorProvideraccepts amaxBodyCaptureBytesprop and forwards it to native via auseEffect.Test plan
[... truncated]markerresponseBodyis[binary content — not captured]maxBodyCaptureBytes={512 * 1024}onNetworkMonitorProvider— confirm larger payloads are now captured up to 512 KBsetMaxBodyCaptureBytes(128 * 1024)directly — confirm cap takes effect on subsequent requests🤖 Generated with Claude Code