diff --git a/http.d b/http.d index 40dbe2d..d9d9ad0 100644 --- a/http.d +++ b/http.d @@ -1,5 +1,7 @@ module http; +import std.exception; + enum HTTPMethod { GET, @@ -32,4 +34,9 @@ struct HTTPResponse string httpVersion = "HTTP/1.1"; } +class HTTPException : Exception +{ + mixin basicExceptionCtors; +} + alias HTTPModule = HTTPResponse delegate (HTTPRequest); diff --git a/httpd.d b/httpd.d index 2a4d251..488262d 100644 --- a/httpd.d +++ b/httpd.d @@ -5,17 +5,11 @@ import http; import std.algorithm; import std.array; import std.conv; -import std.exception; import std.format; import std.socket; import std.stdio; import std.string; -class HttpdException : Exception -{ - mixin basicExceptionCtors; -} - int main(string[] args) { @@ -65,7 +59,7 @@ tryRequest(char[] requestBody) || rq.resource == "/index.html" ? respondWithPage(import("index.html")) : failurePage("404 Not Found"); - } catch (HttpdException e) + } catch (HTTPException e) return failurePage(e.msg); } @@ -172,7 +166,7 @@ parseHTTPRequestHeading(string heading) result.method = HTTPMethod.TRACE; break; default: - throw new HttpdException("400 Bad Request"); + throw new HTTPException("400 Bad Request"); } tup = heading.findSplit(" "); @@ -183,7 +177,7 @@ parseHTTPRequestHeading(string heading) params = params.length == path.length ? "" : params; if (path.length == 0 || path[0] != '/') - throw new HttpdException("400 Bad Request"); + throw new HTTPException("400 Bad Request"); result.path = path;