MCPcopy
hub / github.com/gofiber/fiber / Test_Proxy_Modify_Response

Function Test_Proxy_Modify_Response

middleware/proxy/proxy_test.go:414–437  ·  view source on GitHub ↗

go test -run Test_Proxy_Modify_Response

(t *testing.T)

Source from the content-addressed store, hash-verified

412
413// go test -run Test_Proxy_Modify_Response
414func Test_Proxy_Modify_Response(t *testing.T) {
415 t.Parallel()
416
417 _, addr := createProxyTestServerIPv4(t, func(c fiber.Ctx) error {
418 return c.Status(500).SendString("not modified")
419 })
420
421 app := fiber.New()
422 app.Use(Balancer(Config{
423 Servers: []string{addr},
424 ModifyResponse: func(c fiber.Ctx) error {
425 c.Response().SetStatusCode(fiber.StatusOK)
426 return c.SendString("modified response")
427 },
428 }))
429
430 resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
431 require.NoError(t, err)
432 require.Equal(t, fiber.StatusOK, resp.StatusCode)
433
434 b, err := io.ReadAll(resp.Body)
435 require.NoError(t, err)
436 require.Equal(t, "modified response", string(b))
437}
438
439// go test -run Test_Proxy_Modify_Request
440func Test_Proxy_Modify_Request(t *testing.T) {

Callers

nothing calls this directly

Calls 8

BalancerFunction · 0.85
TestMethod · 0.80
SendStringMethod · 0.65
StatusMethod · 0.65
NewMethod · 0.65
UseMethod · 0.65
ResponseMethod · 0.65

Tested by

no test coverage detected