diff options
author | bptato <nincsnevem662@gmail.com> | 2022-05-10 23:14:05 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-05-10 23:48:32 +0200 |
commit | 4c959684a4bd4705b4176140092e833dfdab7b7a (patch) | |
tree | 72d624bcd5de2dc6e5cd8be6105ad1c71bfc6a39 /src/io/loader.nim | |
parent | f0241b2fec3e41744aa0c900fc4e6d3c46fe4757 (diff) | |
download | chawan-4c959684a4bd4705b4176140092e833dfdab7b7a.tar.gz |
Slightly change header handling
Diffstat (limited to 'src/io/loader.nim')
-rw-r--r-- | src/io/loader.nim | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim index 03834dc3..235466e9 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -9,6 +9,7 @@ import utils/twtstr type FileLoader* = ref object http: HttpClient + headers: HttpHeaders LoadResult* = object s*: Stream @@ -22,11 +23,18 @@ const DefaultHeaders = { "Cache-control": "no-cache", } -proc newFileLoader*(): FileLoader = +proc newFileLoader*(headers: HttpHeaders): FileLoader = new(result) result.http = newHttpClient() -proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, mimetype = "", body: string = "", multipart: MultipartData = nil): LoadResult = +proc newFileLoader*(): FileLoader = + var headers = newHttpHeaders(true) + for header in DefaultHeaders: + headers[header[0]] = header[1] + newFileLoader(headers) + +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_dos() @@ -36,8 +44,7 @@ proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, mimet result.s = newFileStream(path, fmRead) elif url.scheme == "http" or url.scheme == "https": var requestheaders = newHttpHeaders(true) - for header in DefaultHeaders: - requestheaders[header[0]] = header[1] + requestheaders.table = loader.headers.table if mimetype != "": requestheaders["Content-Type"] = mimetype let resp = loader.http.request(url.serialize(true), smethod, body, requestheaders, multipart) |