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

Function Test_Proxy_Domain_Forward_Local

middleware/proxy/proxy_test.go:977–1010  ·  view source on GitHub ↗

go test -run Test_Proxy_Domain_Forward_Local

(t *testing.T)

Source from the content-addressed store, hash-verified

975
976// go test -run Test_Proxy_Domain_Forward_Local
977func Test_Proxy_Domain_Forward_Local(t *testing.T) {
978 t.Parallel()
979 ln, err := net.Listen(fiber.NetworkTCP4, "127.0.0.1:0")
980 require.NoError(t, err)
981 app := fiber.New()
982
983 // target server
984 ln1, err := net.Listen(fiber.NetworkTCP4, "127.0.0.1:0")
985 require.NoError(t, err)
986 app1 := fiber.New()
987
988 app1.Get("/test", func(c fiber.Ctx) error {
989 return c.SendString("test_local_client:" + c.Query("query_test"))
990 })
991
992 proxyAddr := ln.Addr().String()
993 targetAddr := ln1.Addr().String()
994 localDomain := strings.Replace(proxyAddr, "127.0.0.1", "localhost", 1)
995 app.Use(DomainForward(localDomain, "http://"+targetAddr, &fasthttp.Client{
996 NoDefaultUserAgentHeader: true,
997 DisablePathNormalizing: true,
998
999 Dial: fasthttp.Dial,
1000 }))
1001 startServer(app, ln)
1002 startServer(app1, ln1)
1003
1004 client := clientpkg.New()
1005 resp, err := client.Get("http://" + localDomain + "/test?query_test=true")
1006 require.NoError(t, err)
1007 require.Equal(t, fiber.StatusOK, resp.StatusCode())
1008 require.Equal(t, "test_local_client:true", string(resp.Body()))
1009 resp.Close()
1010}
1011
1012// go test -run Test_Proxy_Balancer_Forward_Local
1013func Test_Proxy_Balancer_Forward_Local(t *testing.T) {

Callers

nothing calls this directly

Calls 14

GetFunction · 0.92
DomainForwardFunction · 0.85
startServerFunction · 0.85
ListenMethod · 0.80
AddrMethod · 0.80
NewMethod · 0.65
GetMethod · 0.65
SendStringMethod · 0.65
QueryMethod · 0.65
StringMethod · 0.65
UseMethod · 0.65
BodyMethod · 0.65

Tested by

no test coverage detected