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;
|
module httpd;
|
||||||
|
|
||||||
import http;
|
import http;
|
||||||
|
import httpmodules;
|
||||||
|
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
import std.array;
|
import std.array;
|
||||||
|
@ -55,15 +56,18 @@ string
|
||||||
tryRequest(char[] requestBody)
|
tryRequest(char[] requestBody)
|
||||||
{
|
{
|
||||||
HTTPRequest rq;
|
HTTPRequest rq;
|
||||||
|
string lastErr;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rq = parseHTTPRequest(requestBody);
|
rq = parseHTTPRequest(requestBody);
|
||||||
if (rq.method != HTTPMethod.GET)
|
foreach (mod; httpModules) {
|
||||||
return failurePage("405 Method Not Allowed");
|
try
|
||||||
return rq.resource == "/"
|
return makeHTTPResponse(mod(rq));
|
||||||
|| rq.resource == "/index.html"
|
catch (HTTPException e)
|
||||||
? respondWithPage(import("index.html"))
|
lastErr = e.msg;
|
||||||
: failurePage("404 Not Found");
|
}
|
||||||
|
/* jump to catch block */
|
||||||
|
throw new HTTPException(lastErr);
|
||||||
} catch (HTTPException e)
|
} catch (HTTPException e)
|
||||||
return failurePage(e.msg);
|
return failurePage(e.msg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue