]> Sergey Matveev's repositories - tofuproxy.git/commitdiff
No redirection for images
authorSergey Matveev <stargrave@stargrave.org>
Mon, 6 Sep 2021 17:58:25 +0000 (20:58 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 6 Sep 2021 17:58:25 +0000 (20:58 +0300)
main.go

diff --git a/main.go b/main.go
index 663bf9508980fd9a3600f7f952b4cfdf1d80c825..a4b8a32d8516dccf757fb1f30a027893381f2f37 100644 (file)
--- a/main.go
+++ b/main.go
@@ -30,6 +30,7 @@ import (
        "net/http"
        "os"
        "os/exec"
+       "path/filepath"
        "strings"
        "time"
 
@@ -49,6 +50,23 @@ var (
 
        CmdDWebP = "dwebp"
        CmdDJXL  = "djxl"
+
+       imageExts = map[string]struct{}{
+               ".apng": {},
+               ".avif": {},
+               ".gif":  {},
+               ".heic": {},
+               ".jp2":  {},
+               ".jpeg": {},
+               ".jpg":  {},
+               ".jxl":  {},
+               ".mng":  {},
+               ".png":  {},
+               ".svg":  {},
+               ".tif":  {},
+               ".tiff": {},
+               ".webp": {},
+       }
 )
 
 func dialTLS(ctx context.Context, network, addr string) (net.Conn, error) {
@@ -237,6 +255,9 @@ func roundTrip(w http.ResponseWriter, req *http.Request) {
                        if strings.Contains(req.Header.Get("User-Agent"), "newsboat/") {
                                goto NoRedir
                        }
+                       if _, ok := imageExts[filepath.Ext(req.URL.Path)]; ok {
+                               goto NoRedir
+                       }
                        redirType = "temporary"
                default:
                        goto NoRedir