Skip to content

Commit 4c33e07

Browse files
authored
add-tests-fix (#395)
* add-tests-fix * bump to 0.13.5 * Add slash
1 parent fbbe156 commit 4c33e07

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

config/config.go

Lines changed: 1 addition & 1 deletion
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.4"
58+
Version = "0.13.5"
5959
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
6060
ConvertLock = cache.New(5*time.Minute, 10*time.Minute)
6161
LocalHostAlias = "local"

handler/router.go

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

112-
log.Tracef("reqURIwithQuery is %s", reqURIwithQuery)
113-
114-
// Replace host in the URL
115-
// realRemoteAddr = strings.Replace(reqURIwithQuery, reqHost, targetHost, 1)
116-
realRemoteAddr, _ = url.JoinPath(targetHost, reqURIwithQuery)
117-
log.Debugf("realRemoteAddr is %s", realRemoteAddr)
112+
realRemoteAddr = targetHost + "/" + reqURIwithQuery
118113
}
119114

120115
// Check if the file extension is allowed and not with image extension

handler/router_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,19 @@ func TestConvertProxyModeNonImageWork(t *testing.T) {
303303
var app = fiber.New()
304304
app.Get("/*", Convert)
305305

306-
url := "http://127.0.0.1:3333/sw.js"
306+
url := "http://127.0.0.1:3333/sw.js?version=13"
307307

308308
resp, _ := requestToServer(url, app, chromeUA, acceptWebP)
309309
defer resp.Body.Close()
310310
assert.Equal(t, http.StatusOK, resp.StatusCode)
311311
assert.Equal(t, "text/javascript; charset=utf-8", resp.Header.Get("Content-Type"))
312+
313+
url = "http://127.0.0.1:3333/sw.js"
314+
315+
resp, _ = requestToServer(url, app, chromeUA, acceptWebP)
316+
defer resp.Body.Close()
317+
assert.Equal(t, http.StatusOK, resp.StatusCode)
318+
assert.Equal(t, "text/javascript; charset=utf-8", resp.Header.Get("Content-Type"))
312319
}
313320

314321
func TestConvertMapProxyModeWork(t *testing.T) {

helper/metadata.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ func WriteMetadata(p, etag string, subdir string) config.MetaFile {
7070
data.Checksum = HashFile(filepath)
7171
}
7272

73-
imageMeta := getImageMeta(filepath)
74-
75-
data.ImageMeta = imageMeta
73+
// Only get image metadata if the file has image extension
74+
if CheckImageExtension(filepath) {
75+
imageMeta := getImageMeta(filepath)
76+
data.ImageMeta = imageMeta
77+
}
7678

7779
buf, _ := json.Marshal(data)
7880
_ = os.WriteFile(path.Join(config.Config.MetadataPath, subdir, data.Id+".json"), buf, 0644)

0 commit comments

Comments
 (0)