Skip to content

Conversation

@arferreira
Copy link
Owner

Summary

  • Add Cookie<T> extractor for deserializing cookies into typed structs
  • Parse Cookie header and deserialize to target type via serde
  • Returns 400 Bad Request if required cookies are missing

Usage

#[derive(Deserialize)]
struct Session {
    session_id: String,
}

#[get("/dashboard")]
async fn dashboard(session: Cookie<Session>) -> Result<Json<Dashboard>> {
    let data = session.into_inner();
    // ...
}

Related Issues

Closes #85

Checklist

  • cargo fmt passes
  • cargo clippy has no warnings
  • Tests pass
  • Documentation updated (if needed)

let json = serde_json::to_string(&cookies)
.map_err(|e| Error::bad_request(format!("Failed to process cookies: {}", e)))?;

let value: T = serde_json::from_str(&json)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serializing to JSON and then deserializing from JSON to T looks interesting. Is this a good approach (genuinely asking)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point! it's a pragmatic shortcut, cookies are always k/v pairs, so the json roundtrip works, but yeah it's not the ideal world, I think maybe a direct Hashmap<String, String> -> T would be cleaner, good candidate for a follow-up improvement.

Copy link
Collaborator

@juv juv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arferreira arferreira requested a review from juv February 11, 2026 00:03
@arferreira arferreira merged commit 61dbdc4 into main Feb 12, 2026
2 checks passed
@arferreira arferreira deleted the add-cookie-extractor branch February 12, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Cookie extractor for typed cookie access

3 participants