about summary refs log tree commit diff stats
path: root/src/types/url.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/types/url.nim')
-rw-r--r--src/types/url.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/types/url.nim b/src/types/url.nim
index 9e323847..b676a2b5 100644
--- a/src/types/url.nim
+++ b/src/types/url.nim
@@ -5,6 +5,8 @@ import std/strutils
 import std/tables
 import std/unicode
 
+import io/bufreader
+import io/bufwriter
 import lib/punycode
 import monoucha/fromjs
 import monoucha/javascript
@@ -85,6 +87,30 @@ type
 jsDestructor(URL)
 jsDestructor(URLSearchParams)
 
+# Forward declarations
+proc parseURL*(input: string; base = none(URL); override = none(URLState)):
+    Option[URL]
+func serialize*(url: URL; excludefragment = false; excludepassword = false):
+    string
+
+proc swrite*(writer: var BufferedWriter; url: URL) =
+  if url != nil:
+    writer.swrite(url.serialize())
+  else:
+    writer.swrite("")
+
+proc sread*(reader: var BufferedReader; url: var URL) =
+  var s: string
+  reader.sread(s)
+  if s == "":
+    url = nil
+  else:
+    let x = parseURL(s)
+    if x.isSome:
+      url = x.get
+    else:
+      url = nil
+
 const EmptyPath = URLPath(opaque: true, s: "")
 const EmptyHost = Host(t: htDomain, domain: "")