Skip to content

Cookie Header should be Map-like #1145

Closed
@seanmonstar

Description

@seanmonstar

We only ever receive headers like this: Cookie: foo=bar; session=sean; hello=world, and having that be a vector of ["foo=bar", "session=sean", "hello=world"] doesn't really help anyone.

Instead, anyone needing to accept cookies would only be looking for a certain name anyways, so this code would be more appropriate:

let maybe_session = req.headers().get::<Cookie>().map(|cookie| cookie.get("session"));

Being a map also helps deal with a common mistake naïve users could make: duplicate names should just be dropped.

Creation of a Cookie header should likewise use a map-like interface.

let mut cookie = Cookie::new();
cookie.set("session", "sean");

// maybe an extend API also? Though we could easily defer to a later release
let pairs = [("foo", "bar"), ("hello", "world")];
cookie.extend(&pairs);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions