diff --git a/docs/services/lambda-web-functions.md b/docs/services/lambda-web-functions.md index 05ca1ca2bf..a74a1aee3e 100644 --- a/docs/services/lambda-web-functions.md +++ b/docs/services/lambda-web-functions.md @@ -103,6 +103,8 @@ The platform answers these cases itself, with the AWS HTML pages and `lambda-web | 504 | `Runtime.RequestTimeout` | No response within the revision's `timeoutSeconds` | | 505 | `Platform.UnsupportedHttpVersion` | HTTP/1.0 | +The `date` header of these pages writes the day with two digits, as on AWS: `Sun, 01 Nov 2026 02:33:33 GMT`. The `400` and `431` pages write a two-digit year as well: `Sun, 01 Nov 26 02:33:34 GMT`. + A URI of 65,535 bytes or more gets an empty `414`, as on AWS. Headers or a request line past 256 KiB get the HTTP server's empty `431` or `414` instead of the AWS answer. A request without a `Host` header cannot be told apart from one for another Floci service, so it does not get `Platform.MissingHostHeader`. ## Logs diff --git a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebDataPlane.java b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebDataPlane.java index b73d84151c..7a0443333d 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebDataPlane.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebDataPlane.java @@ -33,8 +33,6 @@ import org.jboss.logging.Logger; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; import java.util.HashSet; import java.util.Locale; import java.util.Map; @@ -67,7 +65,6 @@ public class LambdaWebDataPlane { private static final Logger LOG = Logger.getLogger(LambdaWebDataPlane.class); private static final String BASE32 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; private static final int REQUEST_ID_LENGTH = 26; - private static final DateTimeFormatter HTTP_DATE = DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneOffset.UTC); /** Floci sees an exit some tens of milliseconds after it. A process that keeps running is not waited for longer. */ private static final Duration EXIT_WAIT = Duration.ofSeconds(1); /** The edge counts the request line, the header lines and the blank line, as the client sent them. */ @@ -637,7 +634,7 @@ public class LambdaWebDataPlane { if (page.errorType() != null) { response.headers().set("lambda-web-error-type", page.errorType()); } - response.headers().set("date", HTTP_DATE.format(Instant.now())); + response.headers().set("date", LambdaWebErrorPages.platformDate(Instant.now())); String html = LambdaWebErrorPages.html(page, requestId); // A HEAD request gets the length of the page it does not get, as on AWS. response.headers().set("content-length", String.valueOf(html.getBytes(StandardCharsets.UTF_8).length)); @@ -672,7 +669,7 @@ public class LambdaWebDataPlane { response.setStatusCode(414).setStatusMessage("URI Too Long"); response.headers().set("connection", "close"); response.headers().set("content-length", "0"); - response.headers().set("date", HTTP_DATE.format(Instant.now())); + response.headers().set("date", LambdaWebErrorPages.platformDate(Instant.now())); response.end().onComplete(ignored -> response.close()); } diff --git a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebErrorPages.java b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebErrorPages.java index 4fc4d0b14e..ba0b317b38 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebErrorPages.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebErrorPages.java @@ -56,6 +56,9 @@ final class LambdaWebErrorPages { /** The edge writes a two-digit year in its Date header. */ private static final DateTimeFormatter EDGE_DATE = DateTimeFormatter.ofPattern("EEE, dd MMM yy HH:mm:ss 'GMT'", Locale.ROOT).withZone(ZoneOffset.UTC); + /** The platform writes a two-digit day, which RFC_1123_DATE_TIME leaves out. */ + private static final DateTimeFormatter PLATFORM_DATE = + DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ROOT).withZone(ZoneOffset.UTC); private LambdaWebErrorPages() { } @@ -70,4 +73,8 @@ final class LambdaWebErrorPages { static String edgeDate(Instant now) { return EDGE_DATE.format(now); } + + static String platformDate(Instant now) { + return PLATFORM_DATE.format(now); + } } diff --git a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebMetadataServer.java b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebMetadataServer.java index 56338d417f..7b6d9e3d09 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebMetadataServer.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebMetadataServer.java @@ -20,10 +20,7 @@ import java.net.URI; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.time.Instant; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -47,8 +44,6 @@ public class LambdaWebMetadataServer { private static final String UNAUTHORIZED = "\"Client.Unauthorized\"\n"; private static final String NOT_FOUND = "404 page not found\n"; private static final String NO_HOST = "Bad Request: missing required Host header"; - private static final DateTimeFormatter HTTP_DATE = - DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ROOT).withZone(ZoneOffset.UTC); private static final Logger LOG = Logger.getLogger(LambdaWebMetadataServer.class); private final Vertx vertx; @@ -170,7 +165,7 @@ public class LambdaWebMetadataServer { if (method == HttpMethod.GET || method == HttpMethod.HEAD) { response.putHeader("Content-Type", HTML); } - response.putHeader("Location", location).putHeader("Date", HTTP_DATE.format(Instant.now())); + response.putHeader("Location", location).putHeader("Date", LambdaWebErrorPages.platformDate(Instant.now())); if (method == HttpMethod.GET) { end(response, "Temporary Redirect.\n\n"); } else if (method == HttpMethod.HEAD) { @@ -182,7 +177,7 @@ public class LambdaWebMetadataServer { private static void answer(HttpServerRequest request, int status, String body) { HttpServerResponse response = request.response().setStatusCode(status) - .putHeader("Date", HTTP_DATE.format(Instant.now())); + .putHeader("Date", LambdaWebErrorPages.platformDate(Instant.now())); if (request.method() == HttpMethod.HEAD) { response.putHeader("Content-Length", String.valueOf(body.getBytes(StandardCharsets.UTF_8).length)).end(); } else { diff --git a/src/test/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebErrorPagesTest.java b/src/test/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebErrorPagesTest.java index 8ea9e3dee2..2d99c27b91 100644 --- a/src/test/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebErrorPagesTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebErrorPagesTest.java @@ -46,6 +46,12 @@ class LambdaWebErrorPagesTest { assertEquals("Thu, 15 Oct 26 23:32:32 GMT", LambdaWebErrorPages.edgeDate(Instant.parse("2026-10-15T23:32:32Z"))); } + @Test + void platformDateHasATwoDigitDay() { + assertEquals("Sun, 01 Nov 2026 02:33:33 GMT", + LambdaWebErrorPages.platformDate(Instant.parse("2026-11-01T02:33:33Z"))); + } + private static int length(LambdaWebErrorPages.Page page) { return LambdaWebErrorPages.html(page, REQUEST_ID).getBytes(StandardCharsets.UTF_8).length; }