From e6950393a754e8ffaafd2d56da6cbdcdd5b10d93 Mon Sep 17 00:00:00 2001
From: Sergey Matveev <stargrave@stargrave.org>
Date: Mon, 6 Sep 2021 20:58:25 +0300
Subject: [PATCH] No redirection for images

---
 main.go | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

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
-- 
2.51.0