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
Support .cookie(...)
for customize()
#3214
Comments
I want to give this a try. See #3215 for my first draft |
One more thing, why Current implement of pub fn cookie(&mut self, cookie: cookie::Cookie<'_>) -> &mut Self {
match cookie.to_string().try_into_value() {
Ok(hdr_val) => self.append_header((header::SET_COOKIE, hdr_val)),
Err(err) => {
self.error = Some(err.into());
self
}
}
} My thought: pub fn cookie(&mut self, cookie: cookie::Cookie<'_>) -> &mut Self {
self.append_header((header::SET_COOKIE, cookie.to_string()))
} Is there any reason to do this conversion? |
To which cookie function do you refer? I implemented this according to https://docs.rs/actix-web/latest/actix_web/struct.HttpResponse.html#method.add_cookie which performs the same check to validate the cookie |
This one: https://docs.rs/actix-web/latest/actix_web/struct.HttpResponseBuilder.html#method.cookie By the way, this implementation saves error to self instead of returning a |
|
I mean, although actix_web::HttpResponse::Ok()
.json(...)
.customize()
.append_header((header::COOKIE, cookie.to_string())); //no need to unwrap() or `?`
Err(err) => self.error = Some(err.into()), However, the actix_web::HttpResponse::Ok()
.json(...)
.customize()
.add_cookie(cookie)?; //need to unwrap() or `?` Return a |
I see your point. I guess it depends if you prefer to fail silently or not. As far as I understand Rust, the idea is usually to make possible errors transparent by using the Result type. I don't know why there are two different implementations to add a cookie |
As #3213 wrote, something like
customize().cookie(...)
.I'm not sure if I need to write more details?
The text was updated successfully, but these errors were encountered: