diff --git a/README.md b/README.md index fb66a17..a6770d7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # 自定义webp-server-go -1. 如果源站没有`etag`, 添加一个默认值, 这是防止很多源站不方便配置; -2. 如果文件非图片类型, 302重定向到源文件 +1. 如果文件非图片类型, 302重定向到源文件
diff --git a/handler/remote.go b/handler/remote.go
index 6db236f..64bd607 100644
--- a/handler/remote.go
+++ b/handler/remote.go
@@ -121,37 +121,23 @@ func fetchRemoteImg(url string, subdir string) config.MetaFile {
}
func pingURL(url string) string {
+ // this function will try to return identifiable info, currently include etag, content-length as string
+ // anything goes wrong, will return ""
var etag, length string
resp, err := http.Head(url)
if err != nil {
- log.Errorf("Connection to remote error when pingUrl: %v", err)
- return generateFallbackIdentifier(url)
+ log.Errorln("Connection to remote error when pingUrl!")
+ return ""
}
defer resp.Body.Close()
if resp.StatusCode == fiber.StatusOK {
- etag = resp.Header.Get("ETag")
- length = resp.Header.Get("Content-Length")
-
- if etag == "" {
- log.Warn("Remote didn't return ETag in header, using Last-Modified if available")
- etag = resp.Header.Get("Last-Modified")
- }
-
- if etag == "" {
- log.Warn("Neither ETag nor Last-Modified available, using fallback identifier")
- etag = generateFallbackIdentifier(url)
- }
- } else {
- log.Warnf("Unexpected status code: %d when pinging URL: %s", resp.StatusCode, url)
- return generateFallbackIdentifier(url)
+ etag = resp.Header.Get("etag")
+ length = resp.Header.Get("content-length")
+ }
+ if etag == "" {
+ log.Info("Remote didn't return etag in header when getRemoteImageInfo, please check.")
}
-
return etag + length
}
-func generateFallbackIdentifier(url string) string {
- // 使用 URL 的哈希值作为稳定的标识符
- return "fallback-" + helper.HashString(url)
-}
-