diff options
author | bptato <nincsnevem662@gmail.com> | 2022-02-08 23:14:53 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-02-08 23:14:53 +0100 |
commit | 4f5e4539a8671a0d67a64ba05d84d62a7c54071d (patch) | |
tree | addd439a8ac99950339b2b34afce086c40758600 /src/io/loader.nim | |
parent | 445c7341c85c94c4fa891f49ff6f4eb87e34b722 (diff) | |
download | chawan-4f5e4539a8671a0d67a64ba05d84d62a7c54071d.tar.gz |
Cleanup form method code
Diffstat (limited to 'src/io/loader.nim')
-rw-r--r-- | src/io/loader.nim | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim index 4bd365a8..4a10d336 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -14,11 +14,19 @@ type s*: Stream contenttype*: string +const DefaultHeaders = { + "User-Agent": "chawan", + "Accept": "text/html", "text/*;q=0.5", + "Accept-Language": "en;q=1.0", + "Pragma": "no-cache", + "Cache-control": "no-cache", +} + proc newFileLoader*(): FileLoader = new(result) result.http = newHttpClient() -proc getPage*(loader: FileLoader, url: Url, smethod: string = "GET", mimetype = "", body: string = "", multipart: MultipartData = nil): LoadResult = +proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, mimetype = "", body: string = "", multipart: MultipartData = nil): LoadResult = if url.scheme == "file": when defined(windows) or defined(OS2) or defined(DOS): let path = url.path.serialize_unicode_windows() @@ -27,12 +35,10 @@ proc getPage*(loader: FileLoader, url: Url, smethod: string = "GET", mimetype = result.contenttype = guessContentType(path) result.s = newFileStream(path, fmRead) elif url.scheme == "http" or url.scheme == "https": - let requestheaders = newHttpHeaders({ "User-Agent": "chawan", "Content-Type": mimetype}, true) - let requestmethod = if smethod == "": - "GET" - else: - smethod - let resp = loader.http.request(url.serialize(true), requestmethod, body, requestheaders, multipart) + var requestheaders = newHttpHeaders(DefaultHeaders, true) + if mimetype != "": + requestheaders["Content-Type"] = mimetype + let resp = loader.http.request(url.serialize(true), smethod, body, requestheaders, multipart) let ct = resp.contentType() if ct != "": result.contenttype = ct.until(';') |