diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-10 23:08:55 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-10 23:08:55 +0100 |
commit | d0690cfea6a87c7b7d801b968b5a1c85d1e99b4f (patch) | |
tree | bbaa67f677b34a283cdc006f915f5d0f8ed51bce /src/loader/loader.nim | |
parent | d961fa11e2841cddaca1ca01fe8625bc6d17929c (diff) | |
download | chawan-d0690cfea6a87c7b7d801b968b5a1c85d1e99b4f.tar.gz |
loader: add rejectHandle
Diffstat (limited to 'src/loader/loader.nim')
-rw-r--r-- | src/loader/loader.nim | 16 |
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: |