aboutsummaryrefslogtreecommitdiff
path: root/src/browser.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser.nim')
-rw-r--r--src/browser.nim33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/browser.nim b/src/browser.nim
new file mode 100644
index 0000000..97713a3
--- /dev/null
+++ b/src/browser.nim
@@ -0,0 +1,33 @@
+import std/strutils, protocols/http, html, uri
+
+let url = "https://example.org:443/index.html"
+# let url = paramStr(1)
+
+proc request(uri: string) =
+ # This is probably the best place to implement scheme-specific stuff
+ let url = parseURL(uri)
+ case url.scheme:
+ of "http", "https":
+ let response = httpRequest(url)
+ renderHTML(response.body)
+ # Exercise: view-source
+ of "view-source":
+ # We must parse the url again without the view-source: prefix
+ let url = uri.split(':', maxsplit=1)[1]
+ let response = httpRequest(parseURL(url))
+ renderSource(response.body)
+ # Exercise: file:// scheme
+ of "file":
+ discard
+ # Exercise: data scheme
+ of "data":
+ discard
+ else:
+ raise newException(Exception, "Not a valid scheme: " & url.scheme)
+
+request(url)
+
+# HTTP/1.1
+# Compression
+# Redirects
+# Caching