httpd: handle httpModules
This commit is contained in:
parent
9d23d3454c
commit
0f6e0a4951
1 changed files with 10 additions and 6 deletions
16
httpd.d
16
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue