修复了路径检查和根路径请求的处理,优化了代码结构。

This commit is contained in:
wood chen 2024-09-29 15:19:57 +08:00
parent 585f9a52b8
commit b85b0c6260

View File

@ -23,9 +23,14 @@ func Convert(c *fiber.Ctx) error {
// 3. pass it to encoder, get the result, send it back
// normal http request will start with /
// 检查路径是否以 "/" 开头
if !strings.HasPrefix(c.Path(), "/") {
_ = c.SendStatus(http.StatusBadRequest)
return nil
return c.SendStatus(http.StatusBadRequest)
}
// 处理根路径请求
if c.Path() == "/" {
return c.SendString("Welcome to WebP Server")
}
var (
@ -64,12 +69,6 @@ func Convert(c *fiber.Ctx) error {
//
//
// 处理根路径请求
if reqURI == "/" {
// 重定向到一个适当的页面或返回一个默认响应
return c.SendString("Welcome to WebP Server")
}
if !isImageFile(filename) {
log.Infof("Non-image file requested: %s, redirecting to original URL", reqURI)
var redirectURL string