diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-14 01:20:44 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-14 01:25:43 +0100 |
commit | 43fa886a8a9fd414647e7557ed70a9d3b6103cae (patch) | |
tree | da702730164e996fae005fd56df686c0c7480315 | |
parent | 7c7ca36ac942e6104dfc6ecc6d4061b983b077fa (diff) | |
download | chawan-43fa886a8a9fd414647e7557ed70a9d3b6103cae.tar.gz |
pager: warn on protocol switching redirects
TODO should be configurable
-rw-r--r-- | src/local/pager.nim | 20 |
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) |