-
-
Notifications
You must be signed in to change notification settings - Fork 232
feat: propagate context to adapters on WithContext #867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: propagate context to adapters on WithContext #867
Conversation
cf62e22 to
d92df8f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #867 +/- ##
==========================================
- Coverage 92.56% 92.50% -0.06%
==========================================
Files 23 23
Lines 5511 5514 +3
==========================================
Hits 5101 5101
- Misses 351 353 +2
- Partials 59 60 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces context propagation improvements by adding WithContext methods to all router adapter context wrappers and middleware conversion functions. The key enhancement allows proper context propagation through adapter-specific context handling instead of relying on a general subContext wrapper.
- Adds
WithContextmethods to all adapter context types for proper context propagation - Introduces middleware conversion functions for each router adapter to enable seamless integration
- Includes comprehensive test coverage to verify context propagation functionality
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| api.go | Adds opportunistic WithContext interface check to improve context propagation |
| adapters/humamux/humamux.go | Implements WithContext method and middleware conversion for Gorilla Mux |
| adapters/humahttprouter/humahttprouter.go | Implements WithContext method and middleware conversion for httprouter |
| adapters/humago/humago.go | Implements WithContext method and middleware conversion for Go stdlib |
| adapters/humagin/humagin.go | Implements WithContext method and middleware conversion for Gin |
| adapters/humafiber/humafiber.go | Implements WithContext method and middleware conversion for Fiber |
| adapters/humaecho/humaecho.go | Implements WithContext method and middleware conversion for Echo |
| adapters/humachi/humachi.go | Implements WithContext method and middleware conversion for Chi |
| adapters/humabunrouter/humabunrouter.go | Implements WithContext methods and middleware conversion for BunRouter |
| Test files | Adds context propagation verification tests for each adapter |
16c161c to
383e38c
Compare
383e38c to
6ef5c50
Compare
This PR introduces:
WithContextmethods to adapters' context for proper context propagation. This is then opportunistically used inhuma.WithContextto avoid the generalsubContext.middlewareconversion functions for each adapterThe new
middlewarefunctions in particular could be exported as utilities. If we do that, we could also deduplicate the newTestWithValueShouldPropagateContextinto a single table-driven test across all adapters.Enhancements to context propagation:
WithContextmethods to propagate context in router-specific context wrappers (bunContext,bunCompatContext,chiContext,echoCtx,fiberWrapper,ginCtx,goContext, andhttprouterContext). These methods create new instances of the context wrappers with the updated context. [1] [2] [3] [4] [5] [6] [7] [8]Middleware handling improvements:
bunrouter,chi,echo,fiber,gin,go, andhttprouter). These functions wrap router-specific middleware into the Huma middleware format, enabling seamless integration. [1] [2] [3] [4] [5] [6]Testing and validation:
WithContextmethod and middleware functionality for each router adapter. These tests ensure that context values are correctly passed through middleware layers and accessible in handlers. [1] [2] [3] [4] [5] [6]Closes #859