Skip to content

feat(core): expose request body content streams - #923

Open
sylvesterkaczmarek wants to merge 5 commits into
openai:mainfrom
sylvesterkaczmarek:feat/http-request-body-content
Open

feat(core): expose request body content streams#923
sylvesterkaczmarek wants to merge 5 commits into
openai:mainfrom
sylvesterkaczmarek:feat/http-request-body-content

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Add HttpRequestBody.content(): InputStream so custom HTTP client implementations can consume request bodies directly as streams.

Addresses the request-body portion of #664.

Problem

HttpResponse.body() already exposes an InputStream, but HttpRequestBody only exposes writeTo(OutputStream). Custom HttpClient adapters therefore have to bridge the push-style request body API themselves.

Changes

  • add a JVM-default content(): InputStream method to HttpRequestBody
  • keep existing third-party implementations compatible by providing a default fallback based on writeTo
  • override the fallback for built-in JSON and multipart bodies
  • stream multipart framing with SequenceInputStream, so InputStream-backed file parts are not buffered into memory
  • add focused Kotlin regression coverage for fallback behavior and byte-for-byte multipart parity
  • add a Java-facing regression proving existing implementations do not need to implement the new method

Compatibility

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

  • branch is based directly on current upstream main at 715a30468d3232a5df4f6c6bec8b2175404eb8b9
  • branch is 0 commits behind upstream
  • diff is limited to HttpRequestBody, built-in request-body implementations, and focused tests
  • focused regression tests are included for Kotlin and Java callers
  • full repository validation is left to GitHub Actions because this environment does not have a complete local checkout/toolchain

Addresses #664

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 21, 2026 10:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +19 to +22
fun content(): InputStream {
val outputStream = ByteArrayOutputStream()
writeTo(outputStream)
return outputStream.toByteArray().inputStream()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant