diff options
| author | bptato <nincsnevem662@gmail.com> | 2022-07-24 23:12:13 +0200 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2022-07-24 23:12:13 +0200 |
| commit | fce9adc58cc762d6f70c1d34ac97efddd171edc7 (patch) | |
| tree | ba8ed510a8f1e409285ef8d6055a2e2dced34b92 /src | |
| parent | 3803b94ffc58fb81e944633e83519b74bca8a7fe (diff) | |
| download | chawan-fce9adc58cc762d6f70c1d34ac97efddd171edc7.tar.gz | |
Remove unmaintained networking calls
Diffstat (limited to 'src')
| -rw-r--r-- | src/bindings/curl.nim | 2 | ||||
| -rw-r--r-- | src/config/config.nim | 9 | ||||
| -rw-r--r-- | src/io/loader.nim | 128 |
3 files changed, 3 insertions, 136 deletions
diff --git a/src/bindings/curl.nim b/src/bindings/curl.nim index cf516d2d..64fce485 100644 --- a/src/bindings/curl.nim +++ b/src/bindings/curl.nim @@ -35,7 +35,7 @@ type curl_mimepart_struct = object curl_mimepart* = ptr curl_mimepart_struct curl_slist_struct = object - curl_slist* = ptr curl_mimepart_struct + curl_slist* = ptr curl_slist_struct CURLoption* {.size: sizeof(cint).} = enum # Long diff --git a/src/config/config.nim b/src/config/config.nim index 5c1d3a16..97b344e2 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -44,8 +44,6 @@ type lemap*: ActionMap stylesheet*: string ambiguous_double*: bool - use_curl*: bool - curl_binary*: string func getRealKey(key: string): string = var realk: string @@ -155,13 +153,6 @@ proc parseConfig(config: var Config, dir: string, t: TomlValue) = else: discard if "inline" in css: config.stylesheet &= css["inline"].s - if "network" in t: - let network = t["network"] - if "use-curl" in network: - let usecurl = network["use-curl"] - if usecurl.b: - config.use_curl = true - config.curl_binary = network["curl-binary"].s proc parseConfig(config: var Config, dir: string, stream: Stream) = config.parseConfig(dir, parseToml(stream)) diff --git a/src/io/loader.nim b/src/io/loader.nim index 5545e7cd..f6af4c87 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -1,12 +1,9 @@ import httpclient import options -import os -import osproc import streams import strutils import bindings/curl -import config/config import types/mime import types/url import utils/twtstr @@ -20,10 +17,6 @@ type s*: Stream contenttype*: string - CurlStream = ref object of StreamObj - f: File - curl: Process - HeaderResult = ref object statusline: bool headers: HttpHeaders @@ -47,8 +40,7 @@ proc newFileLoader*(): FileLoader = headers[header[0]] = header[1] newFileLoader(headers) -# copy paste from stdlib for compatibility -# ew. +#TODO replace this with our own multipart object type MultipartEntryClone* = object name, content: string @@ -62,24 +54,6 @@ type MultipartDataClone* = ref object content: seq[MultipartEntryClone] -proc fsAtEnd(s: Stream): bool = return endOfFile(CurlStream(s).f) -proc fsSetPosition(s: Stream, pos: int) = setFilePos(CurlStream(s).f, pos) -proc fsGetPosition(s: Stream): int = return int(getFilePos(CurlStream(s).f)) - -proc fsReadData(s: Stream, buffer: pointer, bufLen: int): int = - result = readBuffer(CurlStream(s).f, buffer, bufLen) - -proc fsReadDataStr(s: Stream, buffer: var string, slice: Slice[int]): int = - result = readBuffer(CurlStream(s).f, addr buffer[slice.a], slice.b + 1 - slice.a) - -proc fsPeekData(s: Stream, buffer: pointer, bufLen: int): int = - let pos = fsGetPosition(s) - defer: fsSetPosition(s, pos) - result = readBuffer(CurlStream(s).f, buffer, bufLen) - -proc fsReadLine(s: Stream, line: var string): bool = - result = readLine(CurlStream(s).f, line) - proc curlWriteHeader(p: cstring, size: csize_t, nitems: csize_t, userdata: pointer): csize_t {.cdecl.} = var line = newString(nitems) for i in 0..<nitems: @@ -183,91 +157,6 @@ proc getPageLibcurl(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, if slist != nil: curl_slist_free_all(slist) -proc getPageCurl(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, mimetype = "", body: string = "", multipart: MultipartDataClone = nil): LoadResult = - var curl_args: seq[string] - - # silent - curl_args.add("-s") - - # follow - curl_args.add("-L") - - # dump headers - curl_args.add("-D") - curl_args.add("/dev/stderr") - - # headers - var requestHeaders = newHttpHeaders(true) - requestHeaders.table = loader.headers.table - if mimetype != "": - requestHeaders["Content-Type"] = mimetype - for k, v in requestHeaders: - curl_args.add("-H") - curl_args.add(k & ": " & v) - - # method - curl_args.add("-X") - curl_args.add($smethod) - - # body - if body != "": - curl_args.add("--data-binary") - curl_args.add(body) - - # multipart - if multipart != nil: - for entry in multipart.content: - if entry.isFile: - #TODO TODO TODO - continue - curl_args.add("--form-string") - curl_args.add(entry.name & '=' & entry.content) - - # url - curl_args.add("--") - curl_args.add(url.serialize(true)) - - # launch - let curl_proc = startProcess(gconfig.curl_binary, "", curl_args, options = {}) - - # output stream - var f: File - if not open(f, curl_proc.outputHandle, fmRead): raiseOSError(osLastError()) - var cs = new(CurlStream) - cs.curl = curl_proc - cs.f = f - cs.readDataImpl = fsReadData - cs.closeImpl = (proc(s: Stream) = CurlStream(s).curl.close()) - cs.atEndImpl = fsAtEnd - cs.readDataStrImpl = fsReadDataStr - cs.readDataImpl = fsReadData - cs.readLineImpl = fsReadLine - cs.peekDataImpl = fsPeekData - result.s = cs - - # response headers - result.contenttype = guessContentType(url.path.serialize()) - let es = curl_proc.errorStream - if not es.atEnd: - discard es.readLine() # status code - var headers = newHttpHeaders(true) - while not es.atEnd: - let line = es.readLine() - let k = line.until(':') - if k.len == line.len: - break # no colon, invalid or empty - so assume headers are done - let v = line.substr(k.len + 1).strip() - headers.add(k, v) - let ct = headers.getOrDefault("Content-Type") - if ct != "": - result.contenttype = ct.until(';') - else: - result.contenttype = guessContentType(url.path.serialize()) - - if curl_proc.peekExitCode() > 0: - result.contenttype = "" - result.s = nil - 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): @@ -277,20 +166,7 @@ proc getPage*(loader: FileLoader, url: Url, smethod: HttpMethod = HttpGet, mimet result.contenttype = guessContentType(path) result.s = newFileStream(path, fmRead) elif url.scheme == "http" or url.scheme == "https": - if gconfig.use_curl: - return getPageLibcurl(loader, url, smethod, mimetype, body, cast[MultipartDataClone](multipart)) - var requestHeaders = newHttpHeaders(true) - requestHeaders.table = loader.headers.table - 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(';') - else: - result.contenttype = guessContentType(url.path.serialize()) - resp.bodystream.setPosition(0) - result.s = resp.bodyStream + return getPageLibcurl(loader, url, smethod, mimetype, body, cast[MultipartDataClone](multipart)) proc getPage*(loader: FileLoader, url: string, smethod: HttpMethod = HttpGet, mimetype = "", body: string = "", multipart: MultipartData = nil): LoadResult = let url = parseUrl(url) |