diff options
author | bptato <nincsnevem662@gmail.com> | 2023-05-14 13:44:59 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-05-14 13:44:59 +0200 |
commit | b080ed197b1f027aa6f400840a4136d1451f9624 (patch) | |
tree | 91345ea92921c60326287a5c3096f46e264a9b59 /src | |
parent | 58dee598d30c5d107f9c469eb01c660b39832f9a (diff) | |
download | chawan-b080ed197b1f027aa6f400840a4136d1451f9624.tar.gz |
Name negative response codes
Diffstat (limited to 'src')
-rw-r--r-- | src/buffer/buffer.nim | 6 | ||||
-rw-r--r-- | src/buffer/container.nim | 2 | ||||
-rw-r--r-- | src/io/loader.nim | 16 |
3 files changed, 17 insertions, 7 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim index bb255f14..2d93214a 100644 --- a/src/buffer/buffer.nim +++ b/src/buffer/buffer.nim @@ -568,6 +568,7 @@ proc loadResources(buffer: Buffer, document: Document): EmptyPromise = return all(promises) type ConnectResult* = object + invalid*: bool code*: int needsAuth*: bool redirect*: Request @@ -577,7 +578,7 @@ type ConnectResult* = object proc setupSource(buffer: Buffer): ConnectResult = if buffer.connected: - result.code = -2 + result.invalid = true return let source = buffer.source let setct = source.contenttype.isNone @@ -586,11 +587,12 @@ proc setupSource(buffer: Buffer): ConnectResult = buffer.url = source.location case source.t of CLONE: + #TODO clone should probably just fork() the buffer instead. let s = connectSocketStream(source.clonepid, blocking = false) buffer.istream = s buffer.fd = cast[int](s.source.getFd()) if buffer.istream == nil: - result.code = -2 + result.code = ERROR_SOURCE_NOT_FOUND return if setct: buffer.contenttype = "text/plain" diff --git a/src/buffer/container.nim b/src/buffer/container.nim index 7dfd26b9..118bb57d 100644 --- a/src/buffer/container.nim +++ b/src/buffer/container.nim @@ -695,7 +695,7 @@ proc load(container: Container) = container.setLoadInfo("Connecting to " & container.location.host & "...") container.iface.connect().then(proc(res: ConnectResult): auto = let info = container.loadinfo - if res.code != -2: + if not res.invalid: container.code = res.code if res.code == 0: container.triggerEvent(SUCCESS) diff --git a/src/io/loader.nim b/src/io/loader.nim index 33b3977f..746c760d 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -49,6 +49,12 @@ type stream: Stream request: Request + ConnectErrorCode* = enum + ERROR_SOURCE_NOT_FOUND = (-4, "clone source could not be found"), + ERROR_LOADER_KILLED = (-3, "loader killed during transfer"), + ERROR_DISALLOWED_URL = (-2, "url not allowed by filter"), + ERROR_UNKNOWN_SCHEME = (-1, "unknown scheme") + LoaderCommand = enum LOAD, QUIT @@ -66,6 +72,9 @@ type cookiejar*: CookieJar referrerpolicy*: ReferrerPolicy +converter toInt*(code: ConnectErrorCode): int = + return int(code) + proc addFd(ctx: LoaderContext, fd: int, flags: int) = ctx.extra_fds.add(curl_waitfd( fd: cast[cint](fd), @@ -85,14 +94,14 @@ proc loadResource(ctx: LoaderContext, request: Request, ostream: Stream) = loadAbout(request, ostream) ostream.close() else: - ostream.swrite(-1) # error + ostream.swrite(ERROR_UNKNOWN_SCHEME) # error ostream.close() proc onLoad(ctx: LoaderContext, stream: Stream) = var request: Request stream.sread(request) if not ctx.config.filter.match(request.url): - stream.swrite(-1) # error + stream.swrite(ERROR_DISALLOWED_URL) # error stream.flush() stream.close() else: @@ -143,8 +152,7 @@ proc finishCurlTransfer(ctx: LoaderContext, handleData: HandleData, res: int) = proc exitLoader(ctx: LoaderContext) = for handleData in ctx.handleList: - #TODO: -1, -2, -3, ... results should be named. - ctx.finishCurlTransfer(handleData, -3) + ctx.finishCurlTransfer(handleData, ERROR_LOADER_KILLED) discard curl_multi_cleanup(ctx.curlm) curl_global_cleanup() ctx.ssock.close() |