mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
* feat(apigatewayv2): HTTP_PROXY integration with request parameter mapping
Adds full HTTP_PROXY support to API Gateway v2 dispatch, replacing the
previous Lambda-only assumption. Integrations with IntegrationType=HTTP_PROXY
now forward the inbound request to the configured IntegrationUri,
applying RequestParameters transformations.
Supported RequestParameters action × target combinations:
overwrite | append | remove × path | header.<name> | querystring.<name>
Supported source value expressions:
$context.authorizer.claims.<name> JWT claim from authorizer
$context.authorizer.<name> authorizer context value
$context.requestId UUID assigned per request
$context.identity.sourceIp client IP
$request.header.<name> case-insensitive header lookup
$request.querystring.<name> query parameter
$request.path.<name> captured path parameter
literal strings returned unchanged
The IntegrationUri may contain {proxy} or {paramName} placeholders,
substituted with captured path parameters from the matched route.
overwrite:path values may also embed $request.path.X / $context.X
substrings which are resolved in-place.
Implementation:
- New package services.apigatewayv2.proxy with RequestContext (DTO),
ContextValueResolver (source expression parser), PathTemplateResolver
(URI template substitution), ProxyRequestBuilder (mutable outgoing
request), RequestParameterMapper (applies RequestParameters), and
HttpProxyInvoker (orchestrator using java.net.http.HttpClient).
- ApiGatewayExecuteController.dispatchV2 now branches on
integration.getIntegrationType() and routes HTTP_PROXY requests to
HttpProxyInvoker, building a RequestContext from the controller state
including parsed JWT claims for $context.authorizer.claims.X.
- Integration v2 model gains a requestParameters Map field, persisted
by ApiGatewayV2Service create/update and serialized by both the
AWS JSON 1.1 handler and the REST controller.
Bug fixes (encountered during integration testing):
- routeKeyMatchesPath now treats `ANY` as the AWS wildcard method,
matching any inbound HTTP method (previously did literal string
comparison and rejected ANY routes for non-ANY requests).
- JWT authorizer audience check now also accepts `client_id` claim,
which Cognito access tokens use instead of `aud` (only ID tokens
carry `aud`). AWS API Gateway accepts either; floci now matches.
Tests:
- 11 ContextValueResolver tests covering each source expression form
- 7 PathTemplateResolver tests covering placeholder substitution
- 13 RequestParameterMapper tests covering each action × target
- 7 HttpProxyInvokerTest tests using JDK com.sun.net.httpserver as a
real backend, verifying method/path/headers/body forwarding,
RequestParameters application, hop-by-hop header stripping, and
502 error mapping for backend failures
- 1 round-trip integration test confirming RequestParameters survive
CreateIntegration → GetIntegration via the AWS JSON 1.1 handler
* perf(apigatewayv2): cache compiled route-template patterns per route key
extractV2PathParams compiled both the routing regex and the
parameter-name extraction regex on every inbound request. Route
keys are stable after creation, so this is wasted work on every
request — visible under load on frequently-hit paths.
Cache the routing regex in a ConcurrentHashMap<String, Pattern>
keyed by the raw template string, and hoist the constant
parameter-name pattern to a static final field.
Adds ApiGatewayExecuteControllerTest with 8 cases covering greedy,
non-greedy, mixed, and edge inputs, plus a hot-loop assertion that
repeated calls against the same route key return stable results
(the cache itself is an internal implementation detail and is not
asserted directly).
* fix(apigatewayv2): accept {name+} greedy placeholder in IntegrationUri
PathTemplateResolver's PLACEHOLDER regex matched {paramName} but not
{paramName+}, so configuring IntegrationUri = "http://backend/{proxy+}"
forwarded the literal string "{proxy+}" to the backend and the call
silently 404'd. The mismatch is surprising because {proxy+} is the
canonical AWS form already accepted by route keys (e.g.
"ANY /wallet/{proxy+}"), so most users mirroring the route shape in
the IntegrationUri hit this.
Extend the placeholder pattern with \+? so {name} and {name+} both
resolve to the same parameter keyed by name. Captured path params
are still stored under the bare name (no + suffix), matching the
existing extractV2PathParams behavior, so no other call sites change.
Picked this over documenting the limitation because the AWS
convention is widely expected and the fix is one character.
Adds 4 tests to PathTemplateResolverTest for {name+}: greedy proxy,
greedy named, mixed greedy + non-greedy, and missing-key fallback.