I'm trying to setting expire in private Cookie in Rust (Rocket Framework version 0.5.0-rc.1) using rocket::http::Cookie
.
In rocket add_private doc I read:
Unless a value is set for the given property, the following defaults are set on cookie before being added to self:
path: "/" SameSite: Strict HttpOnly: true Expires: 1 week from now
I don't understand how to set the Expires property.
I tried to create a new cookie and setting expire using .set_expires() (as in doc example), but it gives me the error: "the trait From<OffsetDateTime>
is not implemented for std::option::Option<time::offset_date_time::OffsetDateTime>
". The code that return the error is something like (values here only for test purpose):
use rocket::http::{Cookie, CookieJar};
use cookie::time::{Duration, OffsetDateTime};
fn handler(jar: &CookieJar<'_>) {
let mut cookie = Cookie::new("name", "value");
let mut now = OffsetDateTime::now_utc();
now += Duration::days(1);
cookie.set_expires(now);
jar.add_private(cookie);
}
I wonder if I have to use cookie crate instead of rocket::http to create the cookie, but in that case I cannot use CookieJar in the response handler because it expected a rocket::http::Cookie and not a cookie::Cookie.
Is there any other way to set an expire or a max age in private cookie using Rocket http module?