http: rename HttpdException to HTTPException

This commit is contained in:
Jeremy Baxter 2024-08-07 13:39:22 +12:00
parent caacad97dd
commit 37a7b67164
2 changed files with 10 additions and 9 deletions

7
http.d
View file

@ -1,5 +1,7 @@
module http; module http;
import std.exception;
enum HTTPMethod enum HTTPMethod
{ {
GET, GET,
@ -32,4 +34,9 @@ struct HTTPResponse
string httpVersion = "HTTP/1.1"; string httpVersion = "HTTP/1.1";
} }
class HTTPException : Exception
{
mixin basicExceptionCtors;
}
alias HTTPModule = HTTPResponse delegate (HTTPRequest); alias HTTPModule = HTTPResponse delegate (HTTPRequest);

12
httpd.d
View file

@ -5,17 +5,11 @@ import http;
import std.algorithm; import std.algorithm;
import std.array; import std.array;
import std.conv; import std.conv;
import std.exception;
import std.format; import std.format;
import std.socket; import std.socket;
import std.stdio; import std.stdio;
import std.string; import std.string;
class HttpdException : Exception
{
mixin basicExceptionCtors;
}
int int
main(string[] args) main(string[] args)
{ {
@ -65,7 +59,7 @@ tryRequest(char[] requestBody)
|| rq.resource == "/index.html" || rq.resource == "/index.html"
? respondWithPage(import("index.html")) ? respondWithPage(import("index.html"))
: failurePage("404 Not Found"); : failurePage("404 Not Found");
} catch (HttpdException e) } catch (HTTPException e)
return failurePage(e.msg); return failurePage(e.msg);
} }
@ -172,7 +166,7 @@ parseHTTPRequestHeading(string heading)
result.method = HTTPMethod.TRACE; result.method = HTTPMethod.TRACE;
break; break;
default: default:
throw new HttpdException("400 Bad Request"); throw new HTTPException("400 Bad Request");
} }
tup = heading.findSplit(" "); tup = heading.findSplit(" ");
@ -183,7 +177,7 @@ parseHTTPRequestHeading(string heading)
params = params.length == path.length ? "" : params; params = params.length == path.length ? "" : params;
if (path.length == 0 || path[0] != '/') if (path.length == 0 || path[0] != '/')
throw new HttpdException("400 Bad Request"); throw new HTTPException("400 Bad Request");
result.path = path; result.path = path;