From 1125206cb326915c25604f36d443384821b30967 Mon Sep 17 00:00:00 2001 From: n0vad3v Date: Mon, 14 Apr 2025 20:42:23 +0800 Subject: [PATCH 1/3] Fix for prefix slash on reqURIwithQuery --- handler/router.go | 4 ++++ handler/router_test.go | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/handler/router.go b/handler/router.go index 213ac549..50a81c09 100644 --- a/handler/router.go +++ b/handler/router.go @@ -109,6 +109,10 @@ func Convert(c *fiber.Ctx) error { reqURIwithQuery = c.OriginalURL() } + // Remove first leading slash from reqURIwithQuery if present + if strings.HasPrefix(reqURIwithQuery, "/") { + reqURIwithQuery = reqURIwithQuery[1:] + } realRemoteAddr = targetHost + "/" + reqURIwithQuery } diff --git a/handler/router_test.go b/handler/router_test.go index dc0b99c9..33ddaf32 100644 --- a/handler/router_test.go +++ b/handler/router_test.go @@ -347,8 +347,9 @@ func TestConvertProxyImgMap(t *testing.T) { config.ProxyMode = false config.Config.ImageMap = map[string]string{ "/2": "../pics/dir1", - "/3": "../pics3", // Invalid path, does not exists - "www.invalid-path.com": "https://docs.webp.sh", // Invalid, it does not start with '/' + "/3": "../pics3", // Invalid path, does not exists + "/s3": "https://d1.awsstatic.com", // AWS S3 bucket for testing query + "www.invalid-path.com": "https://docs.webp.sh", // Invalid, it does not start with '/' "/www.weird-path.com": "https://docs.webp.sh", "/www.even-more-werid-path.com": "https://docs.webp.sh/images", "http://example.com": "https://docs.webp.sh", @@ -363,6 +364,8 @@ func TestConvertProxyImgMap(t *testing.T) { "http://127.0.0.1:3333/www.weird-path.com/images/webp_server.jpg": "image/webp", "http://127.0.0.1:3333/www.even-more-werid-path.com/webp_server.jpg": "image/webp", "http://example.com//images/webp_server.jpg": "image/webp", + + "http://127.0.0.1:3333/s3/s3-pdp-redesign/product-page-diagram_Amazon-S3_HIW%402x.ee85671fe5c9ccc2ee5c5352a769d7b03d7c0f16.png": "image/webp", } var testUrlsLegacy = map[string]string{ From 098118f8c981f0cb832578f2913c3b672df55dad Mon Sep 17 00:00:00 2001 From: n0vad3v Date: Mon, 14 Apr 2025 20:43:22 +0800 Subject: [PATCH 2/3] bump to 0.13.6 --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 5474591c..9315eb5f 100644 --- a/config/config.go +++ b/config/config.go @@ -55,7 +55,7 @@ var ( PrefetchForeground bool // Standalone prefetch, prefetch and exit AllowNonImage bool Config = NewWebPConfig() - Version = "0.13.5" + Version = "0.13.6" WriteLock = cache.New(5*time.Minute, 10*time.Minute) ConvertLock = cache.New(5*time.Minute, 10*time.Minute) LocalHostAlias = "local" From 4821118100ae9e371d1624b24ffce200e78fd560 Mon Sep 17 00:00:00 2001 From: n0vad3v Date: Thu, 24 Apr 2025 16:49:33 +0800 Subject: [PATCH 3/3] Should switch proxyMode after ENV --- config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 9315eb5f..0699ba64 100644 --- a/config/config.go +++ b/config/config.go @@ -164,8 +164,6 @@ func LoadConfig() { decoder := json.NewDecoder(jsonObject) _ = decoder.Decode(&Config) _ = jsonObject.Close() - switchProxyMode() - Config.ImageMap = parseImgMap(Config.ImageMap) if slices.Contains(Config.ConvertTypes, "webp") { Config.EnableWebP = true @@ -304,6 +302,8 @@ func LoadConfig() { if Config.AllowedTypes[0] == "*" { AllowAllExtensions = true } + switchProxyMode() + Config.ImageMap = parseImgMap(Config.ImageMap) log.Debugln("Config init complete") log.Debugln("Config", Config)