Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 5 additions & 2 deletions handler/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
Expand Down
Loading