about summary refs log tree commit diff stats
path: root/src/display
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-13 03:00:16 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-13 03:01:10 +0100
commit1b9c56ac70d8a0af3cd39ba0d49f7651f6ac8fb4 (patch)
tree9a6c879b129c6e95d5b090dcc7f7b0078f666a2a /src/display
parent89750ef4ad621fe7fdce533d1265f3d970098a19 (diff)
downloadchawan-1b9c56ac70d8a0af3cd39ba0d49f7651f6ac8fb4.tar.gz
Add network.max-redirect, prepend-https options
Diffstat (limited to 'src/display')
-rw-r--r--src/display/pager.nim23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/display/pager.nim b/src/display/pager.nim
index 66280edc..d1eca1d7 100644
--- a/src/display/pager.nim
+++ b/src/display/pager.nim
@@ -302,6 +302,7 @@ proc redraw(pager: Pager) {.jsfunc.} =
   pager.term.clearCanvas()
 
 proc draw*(pager: Pager) =
+  if pager.container == nil: return
   pager.term.hideCursor()
   if pager.redraw:
     pager.refreshDisplay()
@@ -522,7 +523,6 @@ proc omniRewrite(pager: Pager, s: string): string =
 # * file://$PWD/<file>
 # * https://<url>
 # So we attempt to load both, and see what works.
-# (TODO: make this optional)
 proc loadURL*(pager: Pager, url: string, ctype = none(string)) =
   let url0 = pager.omniRewrite(url)
   let url = if url[0] == '~': expandPath(url0) else: url0
@@ -535,19 +535,15 @@ proc loadURL*(pager: Pager, url: string, ctype = none(string)) =
     pager.gotoURL(newRequest(firstparse.get), prev, ctype)
     return
   var urls: seq[URL]
-  if url[0] != '/':
+  if pager.config.prependhttps and url[0] != '/':
     let pageurl = parseURL("https://" & url)
     if pageurl.isSome: # attempt to load remote page
       urls.add(pageurl.get)
-  let cdir = parseURL("file://" & getCurrentDir() & DirSep)
-  let purl = percentEncode(url, LocalPathPercentEncodeSet)
-  if purl != url:
-    let newurl = parseURL(purl, cdir)
-    if newurl.isSome:
-      urls.add(newurl.get)
-  let localurl = parseURL(url, cdir)
-  if localurl.isSome: # attempt to load local file
-    urls.add(localurl.get)
+  let cdir = parseURL("file://" & percentEncode(getCurrentDir(), LocalPathPercentEncodeSet) & DirSep)
+  let localurl = percentEncode(url, LocalPathPercentEncodeSet)
+  let newurl = parseURL(localurl, cdir)
+  if newurl.isSome:
+    urls.add(newurl.get) # attempt to load local file
   if urls.len == 0:
     pager.alert("Invalid URL " & url)
   else:
@@ -713,12 +709,15 @@ proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bo
     if pager.container == container:
       pager.authorize()
   of REDIRECT:
-    if container.redirectdepth < 10:
+    if container.redirectdepth < pager.config.maxredirect:
       let redirect = event.location
       pager.alert("Redirecting to " & $redirect)
       pager.gotoURL(newRequest(redirect), some(container.source.location), replace = container, redirectdepth = container.redirectdepth + 1)
     else:
       pager.alert("Error: maximum redirection depth reached")
+      pager.deleteContainer(container)
+      if pager.container == nil:
+        return false
   of ANCHOR:
     var url2 = newURL(container.source.location)
     url2.hash(event.anchor)