aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-08-03 20:27:13 +0200
committerbptato <nincsnevem662@gmail.com>2022-08-03 20:27:13 +0200
commit7f537f7991c384fd88fb1fecf6aa5c05edb6baee (patch)
treeec54215734fb56f283348dbd752823ae7bd329b6 /src
parent46b749e8372b018e73aacc50e908dc96155bcaf8 (diff)
downloadchawan-7f537f7991c384fd88fb1fecf6aa5c05edb6baee.tar.gz
Slightly better handling of http auth + redirect
Diffstat (limited to 'src')
-rw-r--r--src/client.nim52
-rw-r--r--src/io/buffer.nim4
2 files changed, 32 insertions, 24 deletions
diff --git a/src/client.nim b/src/client.nim
index 7bb0721e..9eec487d 100644
--- a/src/client.nim
+++ b/src/client.nim
@@ -476,33 +476,41 @@ proc input(client: Client) =
of ACTION_SEARCH_PREV: client.searchPrev()
else: discard
+proc followRedirect(client: Client)
+
proc checkAuth(client: Client) =
- client.statusMode()
- var username = ""
- let ustatus = readLine("Username: ", username, client.buffer.width)
- if not ustatus:
- client.needsauth = false
- return
- client.statusMode()
- var password = ""
- let pstatus = readLine("Password: ", password, client.buffer.width, hide = true)
- if not pstatus:
- client.needsauth = false
- return
- var url = client.buffer.location
- url.username = username
- url.password = password
- var buf = client.buffer
- client.gotoUrl(url, prevurl = some(client.buffer.location))
- discardBuffer(buf)
+ if client.needsauth:
+ client.buffer.refreshBuffer()
+ client.statusMode()
+ var username = ""
+ let ustatus = readLine("Username: ", username, client.buffer.width)
+ if not ustatus:
+ client.needsauth = false
+ return
+ client.statusMode()
+ var password = ""
+ let pstatus = readLine("Password: ", password, client.buffer.width, hide = true)
+ if not pstatus:
+ client.needsauth = false
+ return
+ var url = client.buffer.location
+ url.username = username
+ url.password = password
+ var buf = client.buffer
+ client.gotoUrl(url, prevurl = some(client.buffer.location))
+ discardBuffer(buf)
+ client.followRedirect()
proc followRedirect(client: Client) =
- if client.redirecturl.issome:
+ while client.redirecturl.issome:
+ client.buffer.refreshBuffer()
var buf = client.buffer
let redirecturl = client.redirecturl.get
client.redirecturl = none(Url)
client.gotoUrl(redirecturl, prevurl = some(client.buffer.location))
discardBuffer(buf)
+ if client.needsauth:
+ client.checkAuth()
proc inputLoop(client: Client) =
while true:
@@ -512,13 +520,11 @@ proc inputLoop(client: Client) =
g_client.buffer.redraw = true
g_client.buffer.reshape = false
g_client.inputLoop())
+ client.followRedirect()
+ client.checkAuth()
client.buffer.refreshBuffer()
- while client.redirecturl.issome:
- client.followRedirect()
- client.buffer.refreshBuffer()
if client.needsauth: # Unauthorized
client.checkAuth()
- client.buffer.refreshBuffer()
try:
client.input()
except ActionError as e:
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index 479297d5..0e50d5fe 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -1245,7 +1245,9 @@ proc refreshBuffer*(buffer: Buffer, peek = false) =
buffer.displayBuffer()
buffer.redraw = false
- buffer.updateHover()
+ if not peek:
+ buffer.updateHover()
+
if buffer.reshape:
buffer.render()
buffer.reshape = false