From: Sergey Matveev Date: Mon, 6 Sep 2021 17:58:25 +0000 (+0300) Subject: No redirection for images X-Git-Tag: v0.1.0~86 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e6950393a754e8ffaafd2d56da6cbdcdd5b10d93;p=tofuproxy.git No redirection for images --- diff --git a/main.go b/main.go index 663bf95..a4b8a32 100644 --- 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