Test_Core_RequestBodyStream() — fiber Function Reference
Architecture documentation for the Test_Core_RequestBodyStream() function in core_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD e859af09_b45a_ced1_41fb_88b2bf439990["Test_Core_RequestBodyStream()"] 35aff514_5856_8aa3_8f9e_63a5c957346d["core_test.go"] e859af09_b45a_ced1_41fb_88b2bf439990 -->|defined in| 35aff514_5856_8aa3_8f9e_63a5c957346d style e859af09_b45a_ced1_41fb_88b2bf439990 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
client/core_test.go lines 398–544
func Test_Core_RequestBodyStream(t *testing.T) {
t.Parallel()
t.Run("request with body stream is properly copied", func(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Post("/echo", func(c fiber.Ctx) error {
body := c.Body()
return c.Send(body)
})
ln := fasthttputil.NewInmemoryListener()
go func() {
err := app.Listener(ln, fiber.ListenConfig{DisableStartupMessage: true})
if err != nil {
panic(err)
}
}()
t.Cleanup(func() {
require.NoError(t, app.Shutdown())
})
client := New().SetDial(func(_ string) (net.Conn, error) {
return ln.Dial()
})
// Create a request with a body stream using SetRawBody which properly sets the body
streamContent := "this is streamed body content"
req := AcquireRequest().SetClient(client)
req.SetURL("http://example.com/echo")
req.SetMethod(fiber.MethodPost)
req.SetRawBody([]byte(streamContent))
resp, err := req.Send()
require.NoError(t, err)
defer resp.Close()
require.Equal(t, streamContent, string(resp.Body()))
})
t.Run("request body stream with content length", func(t *testing.T) {
t.Parallel()
resultCh := make(chan struct {
body string
length int
}, 1)
app := fiber.New()
app.Post("/check-length", func(c fiber.Ctx) error {
resultCh <- struct {
body string
length int
}{
body: string(c.Body()),
length: c.Request().Header.ContentLength(),
}
return c.SendString("ok")
})
ln := fasthttputil.NewInmemoryListener()
go func() {
err := app.Listener(ln, fiber.ListenConfig{DisableStartupMessage: true})
if err != nil {
panic(err)
}
}()
t.Cleanup(func() {
require.NoError(t, app.Shutdown())
})
client := New().SetDial(func(_ string) (net.Conn, error) {
return ln.Dial()
})
streamContent := "body with known length"
req := AcquireRequest().SetClient(client)
req.SetURL("http://example.com/check-length")
req.SetMethod(fiber.MethodPost)
req.SetRawBody([]byte(streamContent))
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Core_RequestBodyStream() do?
Test_Core_RequestBodyStream() is a function in the fiber codebase, defined in client/core_test.go.
Where is Test_Core_RequestBodyStream() defined?
Test_Core_RequestBodyStream() is defined in client/core_test.go at line 398.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free