about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-14 01:20:44 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-14 01:25:43 +0100
commit43fa886a8a9fd414647e7557ed70a9d3b6103cae (patch)
treeda702730164e996fae005fd56df686c0c7480315
parent7c7ca36ac942e6104dfc6ecc6d4061b983b077fa (diff)
downloadchawan-43fa886a8a9fd414647e7557ed70a9d3b6103cae.tar.gz
pager: warn on protocol switching redirects
TODO should be configurable
-rw-r--r--src/local/pager.nim20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 0744a151..c89a35fb 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -1176,6 +1176,11 @@ proc checkMailcap(pager: Pager, container: Container): CheckMailcapResult =
         return pager.runMailcapReadFile(container, entry[], cmd, outpath)
   return (nil, true)
 
+proc redirectTo(pager: Pager, container: Container, request: Request) =
+  pager.alert("Redirecting to " & $request.url)
+  pager.gotoURL(request, some(container.location), replace = container,
+    redirectdepth = container.redirectdepth + 1, referrer = pager.container)
+
 proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bool =
   case event.t
   of FAIL:
@@ -1219,10 +1224,17 @@ proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bo
       pager.authorize()
   of REDIRECT:
     if container.redirectdepth < pager.config.network.max_redirect:
-      pager.alert("Redirecting to " & $event.request.url)
-      pager.gotoURL(event.request, some(container.location),
-        replace = container, redirectdepth = container.redirectdepth + 1,
-        referrer = pager.container)
+      let url = event.request.url
+      if container.location.scheme == url.scheme or
+          container.location.scheme == "cgi-bin" or
+          container.location.scheme == "http" and url.scheme == "https" or
+          container.location.scheme == "https" and url.scheme == "http":
+        pager.redirectTo(container, event.request)
+      else:
+        pager.ask("Warning: switch protocols? " & $url).then(proc(x: bool) =
+          if x:
+            pager.redirectTo(container, event.request)
+        )
     else:
       pager.alert("Error: maximum redirection depth reached")
       pager.deleteContainer(container)