diff options
author | j-james | 2022-06-02 22:02:46 +0000 |
---|---|---|
committer | j-james | 2022-06-24 06:23:44 +0000 |
commit | b629bff6211a18327d49d34eaee5a98471308030 (patch) | |
tree | 68ac42d82fdbaaf1dac6377118108bb69c389b3a /src/browser.nim |
Basic HTTP support and URL parsing
Diffstat (limited to 'src/browser.nim')
-rw-r--r-- | src/browser.nim | 33 |
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 |