Skip to content

Commit 6dbc328

Browse files
authored
Fix for prefix slash on reqURIwithQuery (#399)
* Fix for prefix slash on reqURIwithQuery * bump to 0.13.6 * Should switch proxyMode after ENV
1 parent 4c33e07 commit 6dbc328

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

config/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var (
5555
PrefetchForeground bool // Standalone prefetch, prefetch and exit
5656
AllowNonImage bool
5757
Config = NewWebPConfig()
58-
Version = "0.13.5"
58+
Version = "0.13.6"
5959
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
6060
ConvertLock = cache.New(5*time.Minute, 10*time.Minute)
6161
LocalHostAlias = "local"
@@ -164,8 +164,6 @@ func LoadConfig() {
164164
decoder := json.NewDecoder(jsonObject)
165165
_ = decoder.Decode(&Config)
166166
_ = jsonObject.Close()
167-
switchProxyMode()
168-
Config.ImageMap = parseImgMap(Config.ImageMap)
169167

170168
if slices.Contains(Config.ConvertTypes, "webp") {
171169
Config.EnableWebP = true
@@ -304,6 +302,8 @@ func LoadConfig() {
304302
if Config.AllowedTypes[0] == "*" {
305303
AllowAllExtensions = true
306304
}
305+
switchProxyMode()
306+
Config.ImageMap = parseImgMap(Config.ImageMap)
307307

308308
log.Debugln("Config init complete")
309309
log.Debugln("Config", Config)

handler/router.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func Convert(c *fiber.Ctx) error {
109109
reqURIwithQuery = c.OriginalURL()
110110
}
111111

112+
// Remove first leading slash from reqURIwithQuery if present
113+
if strings.HasPrefix(reqURIwithQuery, "/") {
114+
reqURIwithQuery = reqURIwithQuery[1:]
115+
}
112116
realRemoteAddr = targetHost + "/" + reqURIwithQuery
113117
}
114118

handler/router_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,9 @@ func TestConvertProxyImgMap(t *testing.T) {
347347
config.ProxyMode = false
348348
config.Config.ImageMap = map[string]string{
349349
"/2": "../pics/dir1",
350-
"/3": "../pics3", // Invalid path, does not exists
351-
"www.invalid-path.com": "https://docs.webp.sh", // Invalid, it does not start with '/'
350+
"/3": "../pics3", // Invalid path, does not exists
351+
"/s3": "https://d1.awsstatic.com", // AWS S3 bucket for testing query
352+
"www.invalid-path.com": "https://docs.webp.sh", // Invalid, it does not start with '/'
352353
"/www.weird-path.com": "https://docs.webp.sh",
353354
"/www.even-more-werid-path.com": "https://docs.webp.sh/images",
354355
"http://example.com": "https://docs.webp.sh",
@@ -363,6 +364,8 @@ func TestConvertProxyImgMap(t *testing.T) {
363364
"http://127.0.0.1:3333/www.weird-path.com/images/webp_server.jpg": "image/webp",
364365
"http://127.0.0.1:3333/www.even-more-werid-path.com/webp_server.jpg": "image/webp",
365366
"http://example.com//images/webp_server.jpg": "image/webp",
367+
368+
"http://127.0.0.1:3333/s3/s3-pdp-redesign/product-page-diagram_Amazon-S3_HIW%402x.ee85671fe5c9ccc2ee5c5352a769d7b03d7c0f16.png": "image/webp",
366369
}
367370

368371
var testUrlsLegacy = map[string]string{

0 commit comments

Comments
 (0)