summaryrefslogtreecommitdiff
path: root/handlers/proxy.go
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2025-10-12 20:17:28 +0900
committerhaturatu <taro@eyes4you.org>2025-10-12 20:17:46 +0900
commit5943ca5e9856b9ec08efc372f1ee515460432620 (patch)
tree55562880591b622de00941fc750cff45d1532558 /handlers/proxy.go
parent96f2fed1577e69b62134187c61a4dcf7d864c52b (diff)
feat(goroutine): workerpool
Diffstat (limited to 'handlers/proxy.go')
-rw-r--r--handlers/proxy.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/handlers/proxy.go b/handlers/proxy.go
index 602fc78..d1f6def 100644
--- a/handlers/proxy.go
+++ b/handlers/proxy.go
@@ -2,6 +2,7 @@ package handlers
import (
"auth-proxy/logging"
+ "auth-proxy/worker"
"net/http"
"net/http/httputil"
"net/url"
@@ -22,15 +23,21 @@ func NewProxy(targetURL string) http.Handler {
director(req) // Run the default director
req.Host = target.Host // Set the Host header to the target's host
- // Log the proxying action
+ // Asynchronously log the proxying action to avoid blocking the request.
+ urlStr := req.URL.String()
ip := logging.GetClientIP(req)
- logging.AppLog.Info("Proxying request", "url", req.URL.String(), "ip", ip)
+ worker.Submit(workerPool, func() {
+ logging.AppLog.Info("Proxying request", "url", urlStr, "ip", ip)
+ })
}
// Custom error handler for logging
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
ip := logging.GetClientIP(r)
- logging.AppLog.Error("Proxy error", "error", err, "ip", ip)
+ // Asynchronously log the proxy error to avoid blocking the response.
+ worker.Submit(workerPool, func() {
+ logging.AppLog.Error("Proxy error", "error", err, "ip", ip)
+ })
http.Error(w, "Proxy Error", http.StatusBadGateway)
}