mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(apigateway): format request times with an English locale (#5093)
* fix(apigateway): format request times with an English locale The REST requestTime, the HTTP API requestContext.time and the Lambda function URL requestContext.time were formatted with "dd/MMM/yyyy:HH:mm:ss Z" under the JVM default locale, so on a non-English machine the month came out localized (e.g. "10月"). A REST context mapping forwards that value into an integration request header, where the JDK HTTP client rejected it and the call failed with 500. Pin the formatters to Locale.ENGLISH, as the WebSocket event builder already does, and have the HTTP API proxy and authorizer events reuse the shared formatter in UTC instead of the system time zone. * test(apigateway): cover HTTP API event times under a non-UTC host Build the HTTP API proxy and REQUEST authorizer events under a Japanese default locale and an Asia/Tokyo default time zone, and assert that requestContext.time has an English month, a +0000 offset and the same instant as timeEpoch. buildRequestAuthorizerEventV2 becomes package-private so the test can reach it.
This commit is contained in:
1 parent
b988a061b4
commit
523003972e
4 files changed
+115
-10
No files matched your search
+7
-9
@@ -3203,9 +3203,9 @@ public class ApiGatewayExecuteController {
|
||||
* Builds a REQUEST authorizer event in payload format version 2.0.
|
||||
* Uses the newer HTTP API-native shape with routeArn, routeKey, rawPath, and requestContext.http.
|
||||
*/
|
||||
private String buildRequestAuthorizerEventV2(String httpMethod, String path, String routeKey,
|
||||
String apiId, String stageName, String region,
|
||||
HttpHeaders headers, UriInfo uriInfo) {
|
||||
String buildRequestAuthorizerEventV2(String httpMethod, String path, String routeKey,
|
||||
String apiId, String stageName, String region,
|
||||
HttpHeaders headers, UriInfo uriInfo) {
|
||||
// rawPath is by contract the raw, unmodified path, so recover the trailing slash the
|
||||
// JAX-RS {proxy} binding stripped. routeArn keeps the normalized path for the same reason
|
||||
// methodArn does in the 1.0 shape above.
|
||||
@@ -3249,8 +3249,7 @@ public class ApiGatewayExecuteController {
|
||||
ctx.put("requestId", UUID.randomUUID().toString());
|
||||
ctx.put("routeKey", routeKey != null ? routeKey : "$default");
|
||||
ctx.put("stage", stageName);
|
||||
ctx.put("time", java.time.format.DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z")
|
||||
.format(java.time.ZonedDateTime.now()));
|
||||
ctx.put("time", GATEWAY_REQUEST_TIME.format(Instant.now().atZone(ZoneOffset.UTC)));
|
||||
ctx.put("timeEpoch", System.currentTimeMillis());
|
||||
|
||||
ObjectNode http = ctx.putObject("http");
|
||||
@@ -3474,8 +3473,7 @@ public class ApiGatewayExecuteController {
|
||||
ctx.put("requestId", requestId);
|
||||
ctx.put("routeKey", routeKey != null ? routeKey : "$default");
|
||||
ctx.put("stage", stageName);
|
||||
ctx.put("time", java.time.format.DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z")
|
||||
.format(java.time.ZonedDateTime.now()));
|
||||
ctx.put("time", GATEWAY_REQUEST_TIME.format(Instant.now().atZone(ZoneOffset.UTC)));
|
||||
ctx.put("timeEpoch", System.currentTimeMillis());
|
||||
|
||||
ObjectNode http = ctx.putObject("http");
|
||||
@@ -3570,8 +3568,8 @@ public class ApiGatewayExecuteController {
|
||||
// ──────────────────────────── Gateway responses ────────────────────────────
|
||||
|
||||
private static final String GATEWAY_RESPONSE_HEADER_PREFIX = "gatewayresponse.header.";
|
||||
private static final DateTimeFormatter GATEWAY_REQUEST_TIME =
|
||||
DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z");
|
||||
static final DateTimeFormatter GATEWAY_REQUEST_TIME =
|
||||
DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z", Locale.ENGLISH);
|
||||
|
||||
/**
|
||||
* The {@code {"message": ...}} answer a REST API gives when it, rather than the integration,
|
||||
|
||||
+2
-1
@@ -161,7 +161,8 @@ public class LambdaUrlInvocationController {
|
||||
ctx.put("requestId", requestId);
|
||||
ctx.put("routeKey", "$default");
|
||||
ctx.put("stage", "$default");
|
||||
ctx.put("time", DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z").withZone(ZoneOffset.UTC).format(Instant.now()));
|
||||
ctx.put("time", DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z", Locale.ENGLISH)
|
||||
.withZone(ZoneOffset.UTC).format(Instant.now()));
|
||||
ctx.put("timeEpoch", System.currentTimeMillis());
|
||||
|
||||
ObjectNode httpNode = ctx.putObject("http");
|
||||
|
||||
Reference in new issue
Block a user