feat(core): expose request body content streams - #923
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d392208bb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fun content(): InputStream { | ||
| val outputStream = ByteArrayOutputStream() | ||
| writeTo(outputStream) | ||
| return outputStream.toByteArray().inputStream() |
There was a problem hiding this comment.
Preserve streaming through the logging body wrapper
When LoggingHttpClient runs at DEBUG level, it replaces the request body with LoggingHttpRequestBody, which does not override content(). A custom HttpClient consuming that body through the new API therefore invokes this fallback, causing LoggingHttpRequestBody.writeTo() to materialize the entire body in a ByteArrayOutputStream before returning; large InputStream-backed multipart uploads consequently lose the streaming behavior introduced here and may exhaust the heap. The logging wrapper needs a streaming content() implementation that preserves its logging behavior.
Useful? React with 👍 / 👎.
Summary
Add
HttpRequestBody.content(): InputStreamso custom HTTP client implementations can consume request bodies directly as streams.Addresses the request-body portion of #664.
Problem
HttpResponse.body()already exposes anInputStream, butHttpRequestBodyonly exposeswriteTo(OutputStream). CustomHttpClientadapters therefore have to bridge the push-style request body API themselves.Changes
content(): InputStreammethod toHttpRequestBodywriteToSequenceInputStream, soInputStream-backed file parts are not buffered into memoryCompatibility
The repository compiles Kotlin interfaces with
-Xjvm-default=all, so the new method is emitted as a Java default interface method. Existing Java and Kotlin implementations are not required to add an override.The fallback implementation buffers only for third-party bodies that do not override
content(). Built-in SDK request bodies override it, including streaming multipart bodies.Validation
mainat715a30468d3232a5df4f6c6bec8b2175404eb8b9HttpRequestBody, built-in request-body implementations, and focused testsAddresses #664