-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
response header rework #1869
response header rework #1869
Conversation
0188f07
to
b476f39
Compare
b476f39
to
b459959
Compare
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.
LGTM
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.
I don't really like .insert_header((name, value))
but I guess it's better than having separate methods for typed and untyped headers and having to come up with distinct names for them. The only other solution I could think of is having the same method on two different traits and users importing the one they prefer (I doubt many people are using both typed and untyped headers in the same module).
Also, I see actix-http has its own typed headers; do these predate the headers crate or is there some other reason they are separate?
In my view, an increased focus on typed headers alleviates this enough to make it worth doing. In most cases you're adding common headers to responses, if we don't have the header someone's after we can add it. Plus typed headers are theoretically cheaper than (string, V) since the HeaderName conversion is free. Do you agree that this trade off becomes more worth it when typed headers are used more liberally? You've pointed out the primary issue with the trait approach; we already have folks getting confused when trying to use extensions_mut for example. There's some foreign trait rules things to workaround to use an external crate. It's come up and we're looking into the viability of it. Either way this PR would be largely similar. |
Yeah, I agree. Still it will be some annoying churn that has to be handled as part of transitioning to actix-web 4.0. Maybe you should consider having these new methods before the next major version and deprecate the old ones so upgrading can be done in independent steps. If it's too much work to backport these, maybe you could keep the old ones around as deprecated for the next major version. |
I'll have a think about keeping old ones, deprecated, to make migration easier. Maybe just on ResponseBuilder where most churn would occur. |
f5f986a
to
e5bb20b
Compare
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.
So much more ergonomic. I like it.
I've added back the response builder methods |
This comment has been minimized.
This comment has been minimized.
Sorry for this false alarm, it's fixed by adding to Cargo.toml:
|
PR Type
Feature
PR Checklist
Overview
This PR normalizes header methods used throughout the crates and enables header K/V pairs to use the same methods on
Response
as the typed headers (and give more attention to typed headers in the process).In general, the signatures have changed from
insert_header(key: K, value: V)
toinsert_header(header: H)
, where H implements a new traitIntoHeaderPair
.The easiest migration is simply to use
insert_header((K, V))
, noting the tuple which implements the new trait for all previously accepted types.