From 0f6e0a495135251bbace4bc825ca6e1ff037c543 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Wed, 7 Aug 2024 14:19:24 +1200 Subject: [PATCH] httpd: handle httpModules --- httpd.d | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/httpd.d b/httpd.d index 0c99cd5..b39dfe0 100644 --- a/httpd.d +++ b/httpd.d @@ -1,6 +1,7 @@ module httpd; import http; +import httpmodules; import std.algorithm; import std.array; @@ -55,15 +56,18 @@ string tryRequest(char[] requestBody) { HTTPRequest rq; + string lastErr; try { rq = parseHTTPRequest(requestBody); - if (rq.method != HTTPMethod.GET) - return failurePage("405 Method Not Allowed"); - return rq.resource == "/" - || rq.resource == "/index.html" - ? respondWithPage(import("index.html")) - : failurePage("404 Not Found"); + foreach (mod; httpModules) { + try + return makeHTTPResponse(mod(rq)); + catch (HTTPException e) + lastErr = e.msg; + } + /* jump to catch block */ + throw new HTTPException(lastErr); } catch (HTTPException e) return failurePage(e.msg); }