Skip to content

📝 [Proposal]: Add support for fasthttp.StreamResponseBody #3425

Open
@gaby

Description

@gaby

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: valyala/fasthttp#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:

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

Metadata

Metadata

Type

No type

Projects

Status

Todo

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions