Rocket: cookies.get_private method not returns a value after server restarting

Created on 11 Mar 2020  路  5Comments  路  Source: SergioBenitez/Rocket

Hello, i don't understand what i'm doing wrong. Hope you'll help me :)

I can get an access to private cookie only until the server restart. The cookie is write correctly and work fine, but when the server restarted, get_private method will return None.

This behavior appears only with the private cookies. With simple cookies every thing works fine.

Rocket.toml:

[global]
secret_key = "w6YGfVU32oxP1e0lgbXd5ihQNC6X8NuEHQENcN7BFeI="

Cargo.toml:

[dependencies]
rocket = { version = "0.4", features = ["private-cookies"] }

[dependencies.rocket_contrib]
version = "0.4"
default-features = false

Server log after starting:

Configured for development.
    => address: localhost
    => port: 8000
    => log: normal
    => workers: 12
    => secret key: provided
    => limits: forms = 32KiB
    => keep-alive: 5s
    => tls: disabled

Index action handler:

#[get("/")]
pub fn index_action(mut cookies: Cookies) -> &'static str {

    // i'm commenting this line for test get_private method after server restarts
    cookies.add_private(Cookie::new("user_id", 1.to_string()));

    println!("{:?}", cookies.get_private("user_id"));

    "Hello, world!"
}
question

All 5 comments

I pasted your route into the session example to be sure and it seems to work. The expiration is a week, and after restarting the server and refreshing the page I see a Some(Cookie { ... }) in the log.

What browser and OS is this? And can you verify through your browser's tools (especially the Network and Storage tabs) that the cookie appears in a Set-Cookie header, is stored by the browser, and is sent back in a Cookie header in all the requests you expect it to be?

I was changed the browser now to Firefox and it works. I don't think that it's will be possible, because of the cookies simple functionality.

I'm used the Chromium:
Version 80.0.3987.87 (Official Build) Built on Ubuntu , running on LinuxMint 19 (64-bit)

With extension:
EditThisCookie

Do you know, how to make it works on Chromium, because it's really strange situation with i'm not faced before ? :)

The EditThisCookie extension might be the issue. Try disabling it temporarily and see if that changes anything. You might need to "allow" cookies from localhost in that extension's settings if it is responsible for blocking cookies.

And after disabling all extensions the problem doesn't disappear.
But i have solved it by installing Google Chrome instead.

Thank you for help!

It wasn't because of Chromium browser. It was because of my google account settings, but i'm not still realized which one is responsible for this behaviour. Really weird situation

Was this page helpful?
0 / 5 - 0 ratings