import std/strutils, protocols/http, formats/[html, uri], gui/terminal
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)
render(parseHTML(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(parseHTML((response.body)))
# Exercise: file:// scheme
of "file":
discard
# Exercise: data scheme
of "data":
discard
else:
raise newException(Exception, "Not a valid scheme: " & url.scheme)
when isMainModule:
request(url)
# HTTP/1.1
# Compression
# Redirects
# Caching