{"id":13550067,"url":"https://github.com/LukeMathWalker/biscotti","last_synced_at":"2025-04-02T23:31:44.108Z","repository":{"id":225770311,"uuid":"766213878","full_name":"LukeMathWalker/biscotti","owner":"LukeMathWalker","description":"A Rust library for managing HTTP cookies.","archived":false,"fork":false,"pushed_at":"2025-03-13T17:14:08.000Z","size":107,"stargazers_count":118,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T02:40:28.394Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LukeMathWalker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-02T16:41:23.000Z","updated_at":"2025-03-13T17:14:11.000Z","dependencies_parsed_at":"2024-03-04T08:25:18.018Z","dependency_job_id":"23a3cc78-202f-42b3-b4a7-b730289fd74e","html_url":"https://github.com/LukeMathWalker/biscotti","commit_stats":null,"previous_names":["lukemathwalker/biscotti"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeMathWalker%2Fbiscotti","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeMathWalker%2Fbiscotti/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeMathWalker%2Fbiscotti/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeMathWalker%2Fbiscotti/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LukeMathWalker","download_url":"https://codeload.github.com/LukeMathWalker/biscotti/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246911098,"owners_count":20853652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:01:28.596Z","updated_at":"2025-04-02T23:31:44.102Z","avatar_url":"https://github.com/LukeMathWalker.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Biscotti\n\n[![Crates.io](https://img.shields.io/crates/v/biscotti)](https://crates.io/crates/biscotti)\n[![Docs.rs](https://docs.rs/biscotti/badge.svg)](https://docs.rs/biscotti)\n\n\u003c!-- cargo-rdme start --\u003e\n\nA crate to handle HTTP cookies in a Rust server.\n\n## Overview\n\nYou can use `biscotti` to handle cookies in your server.\n\nIt has support for:\n\n- Handling cookies attached to incoming requests, via `RequestCookies`\n- Building cookies for outgoing responses, via `ResponseCookies`\n- Encrypting, signing or encoding cookies, via `Processor`\n\nIn particular:\n\n- It can handle multiple request cookies with the same name\n- It lets you add multiple cookies with the same name but different paths or domains\n- Cookies are percent-encoded/decoded by default (but you can opt out)\n- It has built-in support for rotating signing/encryption keys over time\n\n## Non-goals\n\n`biscotti` is not designed to handle cookies on the client side.\nIt doesn't provide any logic to parse the `Set-Cookie` headers returned in a server response.\n\n## Quickstart\n\n### Incoming cookies\n\n```rust\nuse biscotti::{Processor, ProcessorConfig, RequestCookies};\n\n// Start by creating a `Processor` instance from a `Config`.\n// It determines if (and which) cookies should be decrypted, verified or percent-decoded.\nlet processor: Processor = ProcessorConfig::default().into();\n// You can then use `RequestCookies::parse_header` to parse the `Cookie` header\n// you received from the client.\nlet cookies = RequestCookies::parse_header(\n    \"name=first%20value; name2=val; name=another%20value\",\n    \u0026processor\n).unwrap();\n\n// You can now access the cookies!\n\n// You can access the first cookie with a given name...\nassert_eq!(cookies.get(\"name\").unwrap().value(), \"first value\");\n// ...or opt to retrieve all values associated with that cookie name.\nassert_eq!(cookies.get_all(\"name\").unwrap().len(), 2);\n\nassert_eq!(cookies.get(\"name2\").unwrap().value(), \"val\");\nassert_eq!(cookies.get_all(\"name2\").unwrap().len(), 1);\n```\n\n### Outgoing cookies\n\n```rust\nuse std::collections::HashSet;\nuse biscotti::{Processor, ProcessorConfig, ResponseCookies, RemovalCookie, ResponseCookie};\nuse biscotti::SameSite;\n\n// Start by creating a `ResponseCookies` instance to hold the cookies you want to send.\nlet mut cookies = ResponseCookies::new();\n\n// You can add cookies to the `ResponseCookies` instance via the `insert` method.\ncookies.insert(ResponseCookie::new(\"name\", \"a value\"));\ncookies.insert(ResponseCookie::new(\"name\", \"a value\").set_path(\"/\"));\n// If you want to remove a cookie from the client's machine, you can use a `RemovalCookie`.\ncookies.insert(RemovalCookie::new(\"another name\"));\n\n// You then convert obtain the respective `Set-Cookie` header values.\n// A processor is required: it determines if (and which) cookies should be encrypted,\n// signed or percent-encoded.\nlet processor: Processor = ProcessorConfig::default().into();\nlet header_values: HashSet\u003c_\u003e = cookies.header_values(\u0026processor).collect();\nassert_eq!(header_values, HashSet::from([\n    \"name=a%20value\".to_string(),\n    // Both `name` cookies are kept since they have different path attributes.\n    \"name=a%20value; Path=/\".to_string(),\n    // A removal cookie is a cookie with an empty value and an expiry in the past.\n    \"another%20name=; Expires=Thu, 01 Jan 1970 00:00:00 GMT\".to_string(),\n]));\n```\n\n### Credits\n\n`biscotti` is heavily inspired by the [`cookie` crate](https://crates.io/crates/cookie) [Copyright (c) 2017 Sergio Benitez,\nCopyright (c) 2014 Alex Crichton].\n`biscotti` started as a `cookie` fork and it includes non-negligible portions of its\ncode.\n\n\n\u003c!-- cargo-rdme end --\u003e\n\n[`Processor`]: https://docs.rs/biscotti/latest/biscotti/struct.Processor.html\n[`RequestCookies`]: https://docs.rs/biscotti/latest/biscotti/struct.RequestCookies.html\n[`ResponseCookies`]: https://docs.rs/biscotti/latest/biscotti/struct.ResponseCookies.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLukeMathWalker%2Fbiscotti","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLukeMathWalker%2Fbiscotti","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLukeMathWalker%2Fbiscotti/lists"}