From 57500621684193e107cb6a242a50f95eed771a6f Mon Sep 17 00:00:00 2001 From: wood chen Date: Sat, 12 Jul 2025 00:49:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E5=9C=A8=E8=AF=B7=E6=B1=82=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E5=AF=BC=E8=87=B4=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=9C=A8=E6=97=A5=E5=BF=97=E4=B8=AD=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=AF=B7=E6=B1=82=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/cache/manager.go | 6 +++++- internal/utils/utils.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/cache/manager.go b/internal/cache/manager.go index 5c40e36..05c423b 100644 --- a/internal/cache/manager.go +++ b/internal/cache/manager.go @@ -230,7 +230,11 @@ func (cm *CacheManager) Put(key CacheKey, resp *http.Response, body []byte) (*Ca } cm.items.Store(key, item) - log.Printf("[Cache] NEW %s %s (%s) from %s", resp.Request.Method, key.URL, formatBytes(item.Size), utils.GetRequestSource(resp.Request)) + method := "GET" + if resp.Request != nil { + method = resp.Request.Method + } + log.Printf("[Cache] NEW %s %s (%s) from %s", method, key.URL, formatBytes(item.Size), utils.GetRequestSource(resp.Request)) return item, nil } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 982293d..9f8e4dc 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -94,6 +94,9 @@ func GenerateRequestID() string { // 获取请求来源 func GetRequestSource(r *http.Request) string { + if r == nil { + return "" + } referer := r.Header.Get("Referer") if referer != "" { return fmt.Sprintf(" (from: %s)", referer)