Upgraded to handy-httpd v8.1.0

This commit is contained in:
Andrew Lalis 2024-01-25 20:31:01 -05:00
parent af0b8b0aab
commit 526f150482
3 changed files with 8 additions and 7 deletions

View File

@ -6,7 +6,7 @@
"dependencies": { "dependencies": {
"d-properties": "~>1.0.4", "d-properties": "~>1.0.4",
"d2sqlite3": "~>1.0.0", "d2sqlite3": "~>1.0.0",
"handy-httpd": "~>7.7.0" "handy-httpd": "~>8.1.0"
}, },
"subConfigurations": { "subConfigurations": {
"d2sqlite3": "all-included" "d2sqlite3": "all-included"

View File

@ -1,11 +1,12 @@
{ {
"fileVersion": 1, "fileVersion": 1,
"versions": { "versions": {
"d-properties": "1.0.4", "d-properties": "1.0.5",
"d2sqlite3": "1.0.0", "d2sqlite3": "1.0.0",
"handy-httpd": "7.7.0", "handy-httpd": "8.1.0",
"httparsed": "1.2.1", "httparsed": "1.2.1",
"slf4d": "2.4.2", "path-matcher": "1.1.3",
"slf4d": "2.4.3",
"streams": "3.5.0" "streams": "3.5.0"
} }
} }

View File

@ -1,5 +1,5 @@
import handy_httpd; import handy_httpd;
import handy_httpd.handlers.path_delegating_handler; import handy_httpd.handlers.path_handler;
import slf4d; import slf4d;
import d_properties; import d_properties;
import d2sqlite3; import d2sqlite3;
@ -54,12 +54,12 @@ void handleVisitorLog(ref HttpRequestContext ctx) {
ctx.response.writeBodyString("Message is too long."); ctx.response.writeBodyString("Message is too long.");
return; return;
} }
if (!ctx.request.hasHeader("X-Forwarded-For")) { if (!ctx.request.headers.contains("X-Forwarded-For")) {
ctx.response.setStatus(HttpStatus.FORBIDDEN); ctx.response.setStatus(HttpStatus.FORBIDDEN);
ctx.response.writeBodyString("Missing remote IP"); ctx.response.writeBodyString("Missing remote IP");
return; return;
} }
string remoteAddress = ctx.request.getHeader("X-Forwarded-For"); string remoteAddress = ctx.request.headers.getFirst("X-Forwarded-For").orElseThrow();
// If the user has sent another log within the last minute, block this one. // If the user has sent another log within the last minute, block this one.
LogEntry[] recentLogsByThisAddress = getRecentLogEntriesByRemoteAddress(remoteAddress); LogEntry[] recentLogsByThisAddress = getRecentLogEntriesByRemoteAddress(remoteAddress);