aboutsummaryrefslogtreecommitdiff
path: root/src/browser.nim
blob: 97713a348591a33e814c1f12cb767dc86f752bcb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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