Skip to content

fix: restore function-based streaming body support (#821)#826

Merged
benoitc merged 2 commits intomasterfrom
fix/function-streaming-body-821
Feb 15, 2026
Merged

fix: restore function-based streaming body support (#821)#826
benoitc merged 2 commits intomasterfrom
fix/function-streaming-body-821

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Feb 15, 2026

Summary

  • Restores function-based streaming body support that was broken in hackney 3.0.2
  • Adds stream_body_fun/3 helper for HTTP/1.1 to iterate over streaming functions
  • Adds stream_body_fun_h3/3 helper for HTTP/3 QUIC connections
  • Modifies streaming_body state handlers to detect function arguments before calling encode_chunk/1

Supported function signatures:

  • Stateless: fun() -> {ok, Data} | eof | {error, Reason}
  • Stateful: fun(State) -> {ok, Data, NewState} | eof | {error, Reason}

Fixes #821

In hackney 1.25.0, send_body/2 accepted functions for iterative body
streaming. In 3.0.2, this was broken because functions were passed
directly to encode_chunk/1 which only handles binary/list data.

This commit adds function handling in the streaming_body state handlers:
- Added stream_body_fun/3 for HTTP/1.1 connections
- Added stream_body_fun_h3/3 for HTTP/3 QUIC connections
- Both support stateless fun() and stateful {fun(State), State} forms
- Functions are iterated until they return eof or error

Supported function signatures:
- Stateless: fun() -> {ok, Data} | eof | {error, Reason}
- Stateful: fun(State) -> {ok, Data, NewState} | eof | {error, Reason}
@benoitc benoitc merged commit b9cbb01 into master Feb 15, 2026
5 checks passed
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.

hackney:send_body does not accept functions anymore

1 participant

Comments