Skip to content

feat(nbhttp): Implement http.Flusher for streaming support#487

Merged
lesismal merged 1 commit intolesismal:masterfrom
DevNewbie1826:fix/http-flush-issue
Aug 8, 2025
Merged

feat(nbhttp): Implement http.Flusher for streaming support#487
lesismal merged 1 commit intolesismal:masterfrom
DevNewbie1826:fix/http-flush-issue

Conversation

@DevNewbie1826
Copy link
Contributor

The existing nbhttp.Response did not implement the http.Flusher interface, preventing its use with http.NewResponseController for streaming data to the client. This was particularly problematic for long-running requests or server-sent events (SSE).

This change introduces full support for http.Flusher and ensures true streaming is possible by automatically enabling chunked encoding when a Content-Length is not explicitly set.

Key changes:

  • Added a Flush() method to Response to implement http.Flusher.
  • Modified checkChunked() to default to Transfer-Encoding: chunked for responses without a Content-Length, which is crucial for streaming.
  • Added a no-op Push() method to satisfy the http.Pusher interface, returning an error as HTTP/2 Push is not supported.

The existing `nbhttp.Response` did not implement the `http.Flusher`
interface, preventing its use with `http.NewResponseController` for
streaming data to the client. This was particularly problematic for
long-running requests or server-sent events (SSE). This change
introduces full support for `http.Flusher` and ensures true streaming is
possible by automatically enabling chunked encoding when a
`Content-Length` is not explicitly set. Key changes: - Added a `Flush()`
method to `Response` to implement `http.Flusher`. - Modified
`checkChunked()` to default to `Transfer-Encoding: chunked` for
responses without a `Content-Length`, which is crucial for streaming. -
Added a no-op `Push()` method to satisfy the `http.Pusher` interface,
returning an error as HTTP/2 Push is not supported.
@lesismal lesismal merged commit 3e45a49 into lesismal:master Aug 8, 2025
7 checks passed
@lesismal
Copy link
Owner

lesismal commented Aug 8, 2025

Thank you for your PR BRO!

@DevNewbie1826 DevNewbie1826 deleted the fix/http-flush-issue branch August 8, 2025 15:02
@lesismal
Copy link
Owner

lesismal commented Aug 9, 2025

v1.6.7 published.

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.

2 participants