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

Function Test_FiberHandler_WithUnixSocket

middleware/adaptor/adaptor_test.go:1554–1581  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1552}
1553
1554func Test_FiberHandler_WithUnixSocket(t *testing.T) {
1555 t.Parallel()
1556
1557 // Test case where request has unix socket context
1558 fiberH := func(c fiber.Ctx) error {
1559 return c.SendString("unix socket success")
1560 }
1561 handlerFunc := FiberHandlerFunc(fiberH)
1562
1563 // Create a context with unix socket local address
1564 unixAddr := &net.UnixAddr{Name: "/tmp/test.sock", Net: "unix"}
1565 ctx := context.WithValue(context.Background(), http.LocalAddrContextKey, unixAddr)
1566
1567 r := &http.Request{
1568 Method: http.MethodGet,
1569 RequestURI: "/test",
1570 RemoteAddr: "someremoteaddr", // This will be ignored due to unix socket
1571 Header: make(http.Header),
1572 Body: http.NoBody,
1573 }
1574 r = r.WithContext(ctx)
1575
1576 w := &netHTTPResponseWriter{}
1577 handlerFunc.ServeHTTP(w, r)
1578
1579 require.Equal(t, http.StatusOK, w.StatusCode())
1580 require.Equal(t, "unix socket success", string(w.body))
1581}
1582
1583func Test_FiberHandler_BodySizeLimit(t *testing.T) {
1584 t.Parallel()

Callers

nothing calls this directly

Calls 5

StatusCodeMethod · 0.95
FiberHandlerFuncFunction · 0.85
SendStringMethod · 0.65
WithContextMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected