about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-10 23:08:55 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-10 23:08:55 +0100
commitd0690cfea6a87c7b7d801b968b5a1c85d1e99b4f (patch)
treebbaa67f677b34a283cdc006f915f5d0f8ed51bce /src
parentd961fa11e2841cddaca1ca01fe8625bc6d17929c (diff)
downloadchawan-d0690cfea6a87c7b7d801b968b5a1c85d1e99b4f.tar.gz
loader: add rejectHandle
Diffstat (limited to 'src')
-rw-r--r--src/loader/loader.nim16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index 53aeb498..fc409a90 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -120,6 +120,10 @@ func canRewriteForCGICompat(ctx: LoaderContext, path: string): bool =
       return true
   return false
 
+proc rejectHandle(handle: LoaderHandle, code: ConnectErrorCode, msg = "") =
+  handle.sendResult(code, msg)
+  handle.close()
+
 proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) =
   var redo = true
   var tries = 0
@@ -164,14 +168,11 @@ proc loadResource(ctx: LoaderContext, request: Request, handle: LoaderHandle) =
         inc tries
         redo = true
       of URI_RESULT_WRONG_URL:
-        handle.sendResult(ERROR_INVALID_URI_METHOD_ENTRY)
-        handle.close()
+        handle.rejectHandle(ERROR_INVALID_URI_METHOD_ENTRY)
       of URI_RESULT_NOT_FOUND:
-        handle.sendResult(ERROR_UNKNOWN_SCHEME)
-        handle.close()
+        handle.rejectHandle(ERROR_UNKNOWN_SCHEME)
   if tries >= MaxRewrites:
-    handle.sendResult(ERROR_TOO_MANY_REWRITES)
-    handle.close()
+    handle.rejectHandle(ERROR_TOO_MANY_REWRITES)
 
 proc onLoad(ctx: LoaderContext, stream: SocketStream) =
   var request: Request
@@ -186,8 +187,7 @@ proc onLoad(ctx: LoaderContext, stream: SocketStream) =
   when defined(debug):
     handle.url = request.url
   if not ctx.config.filter.match(request.url):
-    handle.sendResult(ERROR_DISALLOWED_URL)
-    handle.close()
+    handle.rejectHandle(ERROR_DISALLOWED_URL)
   else:
     for k, v in ctx.config.defaultheaders.table:
       if k notin request.headers.table: