fiber icon indicating copy to clipboard operation
fiber copied to clipboard

šŸ“ [Proposal]: Add support for fasthttp.StreamResponseBody

Open gaby opened this issue 8 months ago • 6 comments

Feature Proposal Description

FastHTTP added support for StreamResponseBody back in 2022 but it was never added to Fiber. The proposal is to make this option available in the Fiber Client and any other places it applies.

Related PR: https://github.com/valyala/fasthttp/pull/1414

Alignment with Express API

N/a

HTTP RFC Standards Compliance

N/a

API Stability

N/a

Feature Examples

req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
defer fasthttp.ReleaseRequest(req)
defer fasthttp.ReleaseResponse(resp)

client := &fasthttp.Client{
    StreamResponseBody: true,
}

req.SetRequestURI("http://example.com/sse")
req.Header.SetMethod("GET")
req.Header.Set("Accept", "text/event-stream")

err := client.Do(req, resp)
if err != nil {
    log.Fatal(err)
}

reader := bufio.NewReader(resp.BodyStream())
for {
    line, err := reader.ReadString('\n')
    if err != nil {
        if err == io.EOF {
            break
        }
        log.Fatal(err)
    }
    fmt.Print("Received:", line)
}

Checklist:

  • [x] I agree to follow Fiber's Code of Conduct.
  • [x] I have searched for existing issues that describe my proposal before opening this one.
  • [x] I understand that a proposal that does not meet these guidelines may be closed without explanation.

gaby avatar Apr 25 '25 11:04 gaby

Hey @gaby I’d love to work on this — please assign it to me

@satti-hari-krishna-reddy Target branch is main. Thanks!

gaby avatar Apr 26 '25 11:04 gaby

@satti-hari-krishna-reddy Any updates on this?

gaby avatar Jul 02 '25 12:07 gaby

@gaby Hello, I'm quite interested in this issue. However, I noticed that the Client struct has already encapsulated the *fasthttp.Client struct, right? Shouldn't setting the StreamResponseBody of *fasthttp.Client to true directly achieve this functionality?

JIeJaitt avatar Jul 15 '25 08:07 JIeJaitt

@gaby is this issue still up for grabs?

Abhirup-99 avatar Aug 17 '25 06:08 Abhirup-99

@Abhirup-99 Yes

gaby avatar Aug 17 '25 06:08 gaby