about summary refs log tree commit diff stats
path: root/src/types
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-03 01:15:11 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-03 01:15:11 +0100
commit4fba568b40e6ca0daab90ca2807c4c58b5405697 (patch)
tree0f2581b9766084600c0da5ecbf1285c8fba28cd0 /src/types
parent15e1b5369542f5f9bc552922a1014ae35999c729 (diff)
downloadchawan-4fba568b40e6ca0daab90ca2807c4c58b5405697.tar.gz
loader: add proper HTTP auth handling
Until now, we just stuffed it into the URL, which was somewhat
problematic.

Mainstream browsers like to hide the username from the user, but I've
decided to follow w3m: buffers do not receive auth info, but the pager
itself displays the username.

As for the origin: I wanted to use the regular origin, but that does not
work with any custom URL.  So instead of changing the regular origin
function, I've added another.
Diffstat (limited to 'src/types')
-rw-r--r--src/types/url.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/types/url.nim b/src/types/url.nim
index 52aa67c3..0c460bbd 100644
--- a/src/types/url.nim
+++ b/src/types/url.nim
@@ -1169,6 +1169,17 @@ proc origin*(url: URL): Origin =
   else:
     return Origin(t: otOpaque, s: $url)
 
+# This follows somewhat different rules from the standard:
+# * with htNone, the origin is opaque.
+# * with other host types, the origin is a tuple origin.
+proc authOrigin*(url: URL): Origin =
+  if url.hostType != htNone:
+    return Origin(
+      t: otTuple,
+      tup: (url.scheme, url.hostname, url.port, none(string))
+    )
+  return Origin(t: otOpaque, s: $url)
+
 proc `==`*(a, b: Origin): bool {.error.} =
   discard