actix-web
actix-web copied to clipboard
extractor for all cookies
Proposal
An AllCookies extractor that can be used in guards.
Discussed in https://github.com/actix/actix-web/discussions/2504
Originally posted by ModProg December 11, 2021
I know that I can parse them manually, but my question is, is there a convenience method like HttpRequest::cookie(&str), to get them from RequestHead in a guard?
And if not, would that be something to consider adding, maybe in a trait both implement?
Is there still demand for this feature (since it has been removed from the milestones)? I would like to try to implement it, if there's any interest left.
Though, this also sounds like a good fit for a third-party crate that takes care of cookies. A third party crate might also help to keep the core part cleaner/ easier to maintain.
The milestone was just a marker for "not due for v4" and has been deleted. So it's open for development.
Okay, I'll take a look at it tomorrow and will prepare a draft. At first glance, it will most likely be an addition to CookieJar (a parse method similar to Cookie::parse) that will be accessible directly or via an extractor.
I have created an issue in the original cookie crate to tackle this issue by extending the underlying library. Once this issue has received an answer, I'll look into building an extractor.
It's been quite some time but the function appears to be added to the lib since a few weeks.
Unfortunately I'm busy with exams for this semester at the moment but I will try to implement it within the next month or so. If someone else wants to try instead, see https://github.com/SergioBenitez/cookie-rs/commit/4295db8671b6561b21d3c29ce26aa6d799dcf926 for the relevant method.
It would be okay to take inspiration from that feature, but we are not able to update the cookie crate to 0.17 without a major version bump. Though if that method is required, there may be a way to add this into actix-web-lab sooner.
I have no requirement for it and due to the age of the PR it most likely has been addressed by the requesting party by now. A non-breaking approach might be to port the code from cookie to a custom Guard and switch to the new cookie version with next actix version bump. Would this fit within the semver approach or would another method be better?