Skip to content

🔥 feat: Add support for streaming response bodies in client and response handling#4014

Merged
ReneWerner87 merged 9 commits intomainfrom
add-support-for-streaming-response-bodies-in-client
Jan 19, 2026
Merged

🔥 feat: Add support for streaming response bodies in client and response handling#4014
ReneWerner87 merged 9 commits intomainfrom
add-support-for-streaming-response-bodies-in-client

Conversation

@ReneWerner87
Copy link
Member

@ReneWerner87 ReneWerner87 commented Jan 17, 2026

Adds client-level streaming controls and response streaming consumption: Client getter/setter for streaming, transport plumbing to propagate the flag across transport types, Response APIs to read/inspect streaming bodies, and core handling changes to preserve streaming during response handling.

Replace #3711
Solves #3425

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds client-level streaming controls and response streaming consumption: Client getter/setter for streaming, transport plumbing to propagate the flag across transport types, Response APIs to read/inspect streaming bodies, and core handling changes to preserve streaming during response handling.

Changes

Cohort / File(s) Summary
Client API
\client/client.go`, `client/client_test.go``
Add StreamResponseBody() bool and SetStreamResponseBody(enable bool) *Client delegating to transport; tests for default, toggle, chaining, and propagation to host/LB clients.
Transport Layer
\client/transport.go`, `client/transport_test.go``
Extend httpClientTransport with StreamResponseBody() and SetStreamResponseBody(enable bool); implement on standardClientTransport, hostClientTransport, and lbClientTransport with traversal/propagation logic; tests cover single/multiple host clients.
Response API
\client/response.go`, `client/response_test.go`, `docs/client/response.md``
Add BodyStream() io.Reader and IsStreaming() bool; make Save() use BodyStream() (streaming or bytes.Reader fallback); tests for streaming, fallback, save semantics, and error paths; docs updated.
Core Request/Response Processing
\client/core.go`, `client/core_test.go``
Nil-guarded deferred ReleaseResponse, preserve request BodyStream when present, and swap fasthttp response into Fiber response (resp.RawResponse) so streams survive CopyTo; tests add transport stubs for streaming methods.
Docs / REST docs
\docs/client/rest.md`, `docs/client/response.md``
Document Client streaming getter/setter and BodyStream usage with examples and consumption notes; update API docs for new Response methods.
Misc
\go.mod``
Module file updated (minor).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client
    participant Transport
    participant Fasthttp as fasthttp.Client
    participant Response

    User->>Client: SetStreamResponseBody(true)
    Client->>Transport: SetStreamResponseBody(true)
    Transport->>Fasthttp: enable StreamResponseBody()

    User->>Client: Do(request)
    Client->>Transport: Do(req)
    Transport->>Fasthttp: Do(req)
    Fasthttp-->>Transport: streaming Response
    Transport-->>Client: Response (RawResponse references fasthttp.Response)
    User->>Response: BodyStream()
    Response-->>User: io.Reader (stream or fallback)
Loading
sequenceDiagram
    participant Core
    participant FasthttpResp as fasthttp.Response
    participant FiberResp as Fiber Response
    participant Defer as Defer Cleanup

    Core->>FasthttpResp: obtain respv
    Core->>FiberResp: swap resp.RawResponse <-> respv
    Core->>Defer: defer ReleaseResponse(respv) (nil-guarded)
    Core-->>FiberResp: return Response with RawResponse referencing fasthttp resp
    Defer-->>FasthttpResp: Release original respv when done
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested labels

📒 Documentation

Suggested reviewers

  • sixcolors
  • efectn
  • gaby

Poem

🐰
I hop where bytes in rivers flow,
I nudge the stream and watch it go.
Swap the raw and keep it bright,
Flags cascade through day and night.
Carrots, code, and streaming light 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provided is minimal and lacks most required sections from the template, including problem statement, detailed changes list, checklist items, documentation updates, and test coverage details. Expand the description to include: detailed problem statement, comprehensive list of changes with checkboxes, documentation and test updates made, and API design rationale.
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main feature being added: streaming support for response bodies in the client and response handling, which is the central focus of all changes across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ReneWerner87 ReneWerner87 linked an issue Jan 17, 2026 that may be closed by this pull request
3 tasks
@ReneWerner87 ReneWerner87 added this to v3 Jan 17, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Jan 17, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ReneWerner87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant feature by adding comprehensive support for streaming response bodies within the client. The primary goal is to improve performance and resource utilization when dealing with large HTTP responses or server-sent events by allowing the response body to be processed as a stream rather than being fully buffered in memory. This is achieved through new client configuration options, dedicated response methods for stream access, and careful integration with the underlying fasthttp library's streaming capabilities.

Highlights

  • Client-side Streaming Configuration: Introduced StreamResponseBody() and SetStreamResponseBody(enable bool) methods to the Client struct, allowing users to enable or disable response body streaming. When enabled, the response body can be read as a stream using BodyStream() instead of being fully loaded into memory, which is beneficial for large responses or server-sent events.
  • Response Body Streaming Access: Added BodyStream() and IsStreaming() methods to the Response struct. BodyStream() provides an io.Reader for the response body, which intelligently falls back to a bytes.Reader if streaming is not enabled. IsStreaming() indicates whether the response body is being streamed.
  • Optimized Response Handling: Modified the internal execFunc in client/core.go to correctly handle request body streaming and to swap fasthttp.Response objects instead of copying them when streaming is enabled. This ensures that the underlying fasthttp stream is preserved and properly released.
  • Transport Layer Integration: The httpClientTransport interface and its concrete implementations (standardClientTransport, hostClientTransport, lbClientTransport) have been updated to include StreamResponseBody() and SetStreamResponseBody() methods, ensuring that the streaming setting is propagated to the underlying fasthttp client types.
  • Enhanced Save() Method: The Save() method in the Response struct now utilizes BodyStream() internally, allowing it to efficiently save streamed response bodies directly to a file or io.Writer without first buffering the entire content into memory.
  • Comprehensive Test Coverage: Extensive unit tests have been added across client_test.go, response_test.go, and transport_test.go to validate the new streaming functionality, covering various scenarios including default values, enabling/disabling streaming, large responses, and interactions with different client and transport types.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.20%. Comparing base (f54a597) to head (5658014).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4014      +/-   ##
==========================================
+ Coverage   91.07%   91.20%   +0.13%     
==========================================
  Files         119      119              
  Lines       10946    11000      +54     
==========================================
+ Hits         9969    10033      +64     
+ Misses        618      611       -7     
+ Partials      359      356       -3     
Flag Coverage Δ
unittests 91.20% <100.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for streaming response bodies, which is a valuable feature for handling large responses efficiently. The implementation is well-structured, with appropriate changes across the client, transport, core, and response components. The new BodyStream() method on the Response is particularly well-designed with its fallback for non-streaming cases. The accompanying tests are mostly comprehensive. I've provided a couple of suggestions to consolidate redundant tests and enhance coverage for the load-balancing client scenario.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for streaming response bodies in the Fiber HTTP client, allowing responses to be read as streams rather than being fully loaded into memory. This addresses issue #3425 and replaces PR #3711, providing the same functionality that exists in the underlying fasthttp library since 2022.

Changes:

  • Added streaming configuration methods at the client level (SetStreamResponseBody/StreamResponseBody)
  • Implemented streaming support across all transport types (standard, host, and load-balanced clients)
  • Enhanced Response API with BodyStream() and IsStreaming() methods
  • Modified response handling logic to preserve body streams during request execution
  • Updated Save() method to use streaming when available

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
client/transport.go Added StreamResponseBody interface methods and implementations for all transport adapters
client/transport_test.go Added comprehensive tests for streaming configuration across all transport types
client/client.go Added public API methods for configuring streaming at the client level
client/client_test.go Added tests for client-level streaming configuration with different transport types
client/response.go Added BodyStream() and IsStreaming() methods; updated Save() to use streaming
client/response_test.go Added extensive tests for streaming functionality and fallback behavior
client/core.go Modified response handling to swap fasthttp responses instead of copying, preserving streams
client/core_test.go Updated mock transport to implement new streaming interface methods

github-actions[bot]

This comment was marked as spam.

@ReneWerner87
Copy link
Member Author

@gaby @grivera64 can you check

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@client/core_test.go`:
- Around line 442-478: The test currently reads receivedContentLength and
receivedBody (set inside the Fiber handler registered via
app.Post("/check-length", ...)) from the main goroutine without synchronization,
causing data races; modify the test to create a channel (e.g., chan struct{ Body
string; Len int }) in the test scope, have the handler send the captured values
into that channel instead of writing shared variables, and in the test goroutine
receive from the channel before doing require.Equal assertions (apply the same
channel pattern for the other similar block around lines 485-525); this keeps
AcquireRequest, New, req.Send and the handler logic intact while eliminating the
race by synchronizing via the channel.

@gaby gaby changed the title feat: add support for streaming response bodies in client and response handling 🔥 feat: Add support for streaming response bodies in client and response handling Jan 18, 2026
@gaby gaby moved this to In Progress in v3 Jan 18, 2026
Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

LGTM overall, just one small thing in the docs.

We could also use io.CopyBuffer with a bytesbufferpool in some places.

@ReneWerner87 ReneWerner87 merged commit 69798d9 into main Jan 19, 2026
18 checks passed
@ReneWerner87 ReneWerner87 deleted the add-support-for-streaming-response-bodies-in-client branch January 19, 2026 07:57
@github-project-automation github-project-automation bot moved this from In Progress to Done in v3 Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

📝 [Proposal]: Add support for fasthttp.StreamResponseBody

3 participants