(t *testing.T, app *fiber.App, configure func(req *fasthttp.Request))
| 42 | } |
| 43 | |
| 44 | func performOversizedRequest(t *testing.T, app *fiber.App, configure func(req *fasthttp.Request)) *fasthttp.Response { |
| 45 | t.Helper() |
| 46 | |
| 47 | ln := fasthttputil.NewInmemoryListener() |
| 48 | errCh := make(chan error, 1) |
| 49 | |
| 50 | go func() { |
| 51 | errCh <- app.Listener(ln, fiber.ListenConfig{DisableStartupMessage: true}) |
| 52 | }() |
| 53 | |
| 54 | t.Cleanup(func() { |
| 55 | require.NoError(t, app.Shutdown()) |
| 56 | if err := <-errCh; err != nil && !errors.Is(err, net.ErrClosed) { |
| 57 | require.NoError(t, err) |
| 58 | } |
| 59 | }) |
| 60 | |
| 61 | require.Eventually(t, func() bool { |
| 62 | conn, err := ln.Dial() |
| 63 | if err != nil { |
| 64 | return false |
| 65 | } |
| 66 | if err := conn.Close(); err != nil { |
| 67 | return false |
| 68 | } |
| 69 | return true |
| 70 | }, time.Second, 10*time.Millisecond) |
| 71 | |
| 72 | req := fasthttp.AcquireRequest() |
| 73 | resp := fasthttp.AcquireResponse() |
| 74 | |
| 75 | req.SetRequestURI("http://example.com/") |
| 76 | req.Header.SetMethod(fiber.MethodPost) |
| 77 | req.Header.Set(fiber.HeaderOrigin, "https://example.com") |
| 78 | req.SetBody(bytes.Repeat([]byte{'a'}, 32)) |
| 79 | if configure != nil { |
| 80 | configure(req) |
| 81 | } |
| 82 | |
| 83 | client := fasthttp.Client{ |
| 84 | Dial: func(string) (net.Conn, error) { |
| 85 | return ln.Dial() |
| 86 | }, |
| 87 | } |
| 88 | |
| 89 | require.NoError(t, client.Do(req, resp)) |
| 90 | |
| 91 | respCopy := fasthttp.AcquireResponse() |
| 92 | resp.CopyTo(respCopy) |
| 93 | |
| 94 | fasthttp.ReleaseRequest(req) |
| 95 | fasthttp.ReleaseResponse(resp) |
| 96 | |
| 97 | t.Cleanup(func() { |
| 98 | fasthttp.ReleaseResponse(respCopy) |
| 99 | }) |
| 100 | |
| 101 | return respCopy |
no test coverage detected