DateHeaderHandler: Unsupported Time‑Zone Offsets in HTTP Date Header
0 reputation · 21 Nov 2023, 00:57 UTC
0 reputation · 21 Nov 2023, 00:57 UTC
Vert.x Web’s DateHeaderHandler parses the HTTP Date header only when the value matches the RFC1123 format in GMT (e.g., Tue, 15 Nov 1994 08:12:31 GMT). A header with a non‑GMT offset, such as Tue, 15 Nov 1994 08:12:31 +0200, results in a parsing exception.
Developers must drop the header or implement a custom handler using java.time.DateTimeFormatter to apply zone conversion. An open GitHub issue requests optional support for arbitrary offsets, but no decision has been made.
Extending the handler would affect backward compatibility, request routing, caching, and performance. The trade‑offs of preserving the original offset versus normalizing to UTC are unclear.
DateHeaderHandler be extended to accept arbitrary time‑zone offsets in the Date header?31775 reputation · 21 Nov 2023, 04:42 UTC
Do not extend DateHeaderHandler to accept arbitrary time‑zone offsets. Keep the current GMT‑only behavior and, if your application receives non‑GMT Date headers, either drop the header before it reaches the handler or provide a custom handler that converts the value to UTC.
The built‑in DateHeaderHandler uses a fixed DateTimeFormatter configured with ZoneOffset.UTC. Consequently, any header containing a numeric offset (e.g., +0200) triggers a DateTimeParseException, resulting in a 400 Bad Request (or the exception propagates per your error handling). This design preserves caching correctness and request‑routing semantics, which rely on a canonical UTC timestamp.
Date header in a preceding filter (e.g., RoutingContext.removeHeader("Date")).public class FlexibleDateHandler implements Handler<RoutingContext> {
private static final DateTimeFormatter RFC1123_WITH_OFFSET =
DateTimeFormatter.RFC_1123_DATE_TIME;
@Override
public void handle(RoutingContext ctx) {
String header = ctx.request().getHeader(HttpHeaders.DATE);
if (header != null) {
try {
ZonedDateTime zdt = ZonedDateTime.parse(header, RFC1123_WITH_OFFSET);
Instant instant = zdt.toInstant(); // normalize to UTC
// store or use the instant as needed, e.g., ctx.put("dateInstant", instant);
} catch (DateTimeParseException e) {
ctx.fail(e);
return;
}
}
ctx.next();
}
}DateHeaderHandler in your router chain.Date header to be a UTC timestamp. Preserving the original offset would break cache validation and could lead to stale responses.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.