feat(launcher): add HTTPMiddleware seam to launcher.Config#974
Open
nuthalapativarun wants to merge 1 commit into
Open
feat(launcher): add HTTPMiddleware seam to launcher.Config#974nuthalapativarun wants to merge 1 commit into
nuthalapativarun wants to merge 1 commit into
Conversation
Add an HTTPMiddleware field to launcher.Config that lets embedders wrap the HTTP handler before the server is created. Middleware is applied outermost-first (slice index 0 runs first on inbound requests), matching the chi.Use / mux.Use convention. The change is purely additive: existing callers that do not set HTTPMiddleware see no behavior difference (the handler is unchanged). Closes google#965
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Root Cause / Motivation
Embedders that wrap ADK Go inside a larger application have no way to insert HTTP middleware into the launcher's request pipeline.
webLauncher.Runbuilds thehttp.Serverdirectly from the router with no public hook for wrapping the handler. The concrete case described in the issue is distributed-tracing context extraction (otelhttp.NewHandler), but the pattern applies to any cross-cutting concern (auth, rate-limiting, request-ID injection, etc.).Change
Add
HTTPMiddleware []func(http.Handler) http.Handlertolauncher.Config:Apply the chain in
webLauncher.Runbefore constructinghttp.Server:The reverse-index loop produces outer-first ordering (slice index 0 runs first on inbound requests), matching
chi.Use/mux.Useconventions. The zero-value (nil slice) is a no-op, so all existing callers are unaffected.Testing Plan
Unit Tests:
TestHTTPMiddleware_AppliedOutermostFirstincmd/launcher/web/web_test.go: starts the web server with two named middlewares, fires a/pingrequest, and asserts that the invocation order matches slice order (["first", "second", ...])../cmd/launcher/...continue to pass.Manual End-to-End (E2E) Tests:
Embedder usage after the change:
Checklist