mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 00:21:56 +08:00
优化缓存管理日志记录,确保在请求为空时不会导致错误,并在日志中正确显示请求方法。
This commit is contained in:
parent
818dd11dda
commit
5750062168
6
internal/cache/manager.go
vendored
6
internal/cache/manager.go
vendored
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user