(t *testing.T)
| 2249 | } |
| 2250 | |
| 2251 | func Test_Client_SetProxyURL(t *testing.T) { |
| 2252 | t.Parallel() |
| 2253 | |
| 2254 | app, dial, start := createHelperServer(t) |
| 2255 | app.Get("/", func(c fiber.Ctx) error { |
| 2256 | return c.SendString(c.Get("isProxy")) |
| 2257 | }) |
| 2258 | |
| 2259 | go start() |
| 2260 | |
| 2261 | fasthttpClient := &fasthttp.Client{ |
| 2262 | Dial: dial, |
| 2263 | NoDefaultUserAgentHeader: true, |
| 2264 | DisablePathNormalizing: true, |
| 2265 | } |
| 2266 | |
| 2267 | // Create a simple proxy server |
| 2268 | proxyServer := fiber.New() |
| 2269 | |
| 2270 | proxyServer.Use("*", func(c fiber.Ctx) error { |
| 2271 | req := fasthttp.AcquireRequest() |
| 2272 | resp := fasthttp.AcquireResponse() |
| 2273 | |
| 2274 | req.SetRequestURI(c.BaseURL()) |
| 2275 | req.Header.SetMethod(fasthttp.MethodGet) |
| 2276 | |
| 2277 | for key, value := range c.Request().Header.All() { |
| 2278 | req.Header.AddBytesKV(key, value) |
| 2279 | } |
| 2280 | |
| 2281 | req.Header.Set("isProxy", "true") |
| 2282 | |
| 2283 | if err := fasthttpClient.Do(req, resp); err != nil { |
| 2284 | return err |
| 2285 | } |
| 2286 | |
| 2287 | c.Status(resp.StatusCode()) |
| 2288 | c.RequestCtx().SetBody(resp.Body()) |
| 2289 | |
| 2290 | return nil |
| 2291 | }) |
| 2292 | |
| 2293 | addrChan := make(chan string) |
| 2294 | go func() { |
| 2295 | assert.NoError(t, proxyServer.Listen(":0", fiber.ListenConfig{ |
| 2296 | DisableStartupMessage: true, |
| 2297 | ListenerAddrFunc: func(addr net.Addr) { |
| 2298 | addrChan <- addr.String() |
| 2299 | }, |
| 2300 | })) |
| 2301 | }() |
| 2302 | |
| 2303 | t.Cleanup(func() { |
| 2304 | require.NoError(t, app.Shutdown()) |
| 2305 | }) |
| 2306 | |
| 2307 | time.Sleep(1 * time.Second) |
| 2308 |
nothing calls this directly
no test coverage detected