-
-
Notifications
You must be signed in to change notification settings - Fork 234
feat: better support for cookies #258
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #258 +/- ##
==========================================
+ Coverage 94.52% 94.65% +0.13%
==========================================
Files 18 18
Lines 2665 2694 +29
==========================================
+ Hits 2519 2550 +31
+ Misses 107 106 -1
+ Partials 39 38 -1 ☔ View full report in Codecov by Sentry. |
|
Looks good for me only minor annoyance in needing to extract single cookie from slice when using |
|
@x-user this was just copied from the standard library, see https://github.com/golang/go/blob/master/src/net/http/cookie.go#L273-L310. I'm open to changing our exported function signature though. |
|
@danielgtaylor i understand this, but standard library uses different public signature func (r *Request) Cookies() []*Cookie
func (r *Request) Cookie(name string) (*Cookie, error) |
|
@x-user take a look at the latest and let me know what you think. |
|
@danielgtaylor, i have no complaints. |
This PR does the following:
cookiefield tag for cookie parameters. Fields can be any of the normal parameter types, plushttp.Cookieis supported to get the entire parsed cookie.huma.ReadCookies(ctx huma.Context, filter string)is provided for reading/parsing cookies from one or moreCookieheaders in a router-agnostic way and without needing to modify thehuma.Contextinterface. This function can be used in middleware to read cookie values.fmt.Stringer(aka aString() stringmethod), then that is used to serialize the header.huma.Context().AppendHeader(...)is used to write multiple headers with the same name.http.Cookieand[]http.Cookieare supported for response headers using theSet-Cookieheader. They basically just work.Fixes #227, #253.