From d3a8da1dcf0d25739ee841b9f25ae7e1038cd513 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Mon, 5 Feb 2024 14:35:33 +0000 Subject: [PATCH] Move location of the global proxy client from the per-req to main. There's no need to re-create it every single time. --- main.go | 2 ++ proxy.go | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 51e8892..0bd8825 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "os" "strings" + "github.com/gofiber/fiber/v2/middleware/proxy" "github.com/gookit/goutil/envutil" graphql "github.com/lukaszraczylo/go-simple-graphql" libpack_config "github.com/lukaszraczylo/graphql-monitoring-proxy/config" @@ -66,6 +67,7 @@ func parseConfig() { }() c.Client.ClientTimeout = getDetailsFromEnv("PROXIED_CLIENT_TIMEOUT", 120) c.Client.FastProxyClient = createFasthttpClient(c.Client.ClientTimeout) + proxy.WithClient(c.Client.FastProxyClient) // setting the global proxy client here instead of per request c.Server.EnableApi = getDetailsFromEnv("ENABLE_API", false) c.Server.ApiPort = getDetailsFromEnv("API_PORT", 9090) c.Api.BannedUsersFile = getDetailsFromEnv("BANNED_USERS_FILE", "/go/src/app/banned_users.json") diff --git a/proxy.go b/proxy.go index 00a1aac..645fb51 100644 --- a/proxy.go +++ b/proxy.go @@ -39,8 +39,6 @@ func proxyTheRequest(c *fiber.Ctx) error { c.Request().Header.Add(fiber.HeaderXForwardedFor, string(c.Request().Header.Peek("X-Forwarded-For"))) c.Request().Header.Del(fiber.HeaderAcceptEncoding) - proxy.WithClient(cfg.Client.FastProxyClient) - cfg.Logger.Debug("Proxying the request", map[string]interface{}{"path": c.Path(), "body": string(c.Request().Body()), "headers": c.GetReqHeaders(), "request_uuid": c.Locals("request_uuid")}) err := proxy.DoRedirects(c, cfg.Server.HostGraphQL+c.Path(), 3) if err != nil {