Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-Cookie header should have a more structured wrapper #1337

Closed
kamalmarhubi opened this issue Sep 26, 2017 · 7 comments
Closed

Set-Cookie header should have a more structured wrapper #1337

kamalmarhubi opened this issue Sep 26, 2017 · 7 comments
Labels
A-headers Area: headers.

Comments

@kamalmarhubi
Copy link

This is an analog of #1145 which was about the Cookie header. The current type is a direct wrapper over the vector of Set-Cookie headers. From some client uses, it would be nice to have a cookie name based lookup, as well as accessors for the "standard" cookie attributes. For server use, it would be nice to expose a builder-type interface to add cookies and set attributes.

It needs some thought to avoid allocations / copies to the degree that makes sense / impossible, but I think the convenience is worth a small penalty for many uses. A possible rough interface:

impl SetCookie {
  pub fn get<K: AsRef<[u8]>(&self, key: K) -> Option<CookieValue> { unimplemented!(); }
  pub fn add<K: AsRef<[u8]>(&self, key: K) -> CookieBuilder  { unimplemented!(); }
}

pub struct CookieValue(/* TBD */);
impl CookieValue {
  pub fn http_only(&self) -> bool  { unimplemented!(); }
  pub fn domain(&self) -> Option<&str>  { unimplemented!(); }
  pub fn extension(&self) -> Option<&str>  { unimplemented!(); }
  // ...
}

pub struct CookieBuilder(/* TBD */);
impl CookieBuilder {
  pub fn http_only(&mut self, http_only: bool) -> &mut CookieBuilder  { unimplemented!(); }
  pub fn domain<S: AsRef<str>>(&mut self, domain: S) -> &mut CookieBuilder  { unimplemented!(); }
  pub fn extension(&mut self, extension: S) -> &mut CookieBuilder  { unimplemented!(); }
  // ...
}

// Maybe for ergonomics?
impl Drop for CookieBuilder {
  pub fn drop(&mut self) {
    // Add the cookie to the storage in `SetCookie`.
  }
}
@seanmonstar
Copy link
Member

Seems like a good goal. Perhaps CookieValue is CookieValue<'a>, which borrows from SetCookie?

@kamalmarhubi
Copy link
Author

Yeah, was thinking something like that. So long as you think it's a good direction, I'll take a crack at it.

And if the Drop ergonomics thing makes sense, then CookieBuilder<'a> with &'a mut SetCookie inside. Not so sure about that one; thoughts?

@kamalmarhubi
Copy link
Author

Oh and one thing I'm unclear on: how much of the "typed header" stuff will remain in Hyper after switching to the http crate's types?

@seanmonstar
Copy link
Member

Oh, I hadn't noticed the Drop behavior. Hm, on one hand, that seems clever, but on the other, it seems surprising...

For 0.12, hyper will have removed hyper::header, and all that was in it will be published as a separate crate (with an altered API to accommodate working with HeaderMaps).

@kamalmarhubi
Copy link
Author

Hm, on one hand, that seems clever, but on the other, it seems surprising...

Yeah, that was my thought too. Thinking a bit more, it should be possible to avoid a "commit" step.

For 0.12, hyper will have removed hyper::header, and all that was in it will be published as a separate crate (with an altered API to accommodate working with HeaderMaps).

What's the timeline for this? Is it worth implementing this against 0.11?

@seanmonstar
Copy link
Member

What's the timeline for this? Is it worth implementing this against 0.11?

There is the 0.12 milestone, but in short, it is waiting for any breaking changes for futures and the tokio crates, to be combined with the breaking change of using http. It will likely be a while, possible a couple months, so this feature could easily fit into 0.11.

@seanmonstar seanmonstar added A-client Area: client. A-headers Area: headers. E-easy Effort: easy. A task that would be a great starting point for a new contributor. C-feature Category: feature. This is adding a new feature. and removed A-client Area: client. labels Sep 27, 2017
@seanmonstar seanmonstar removed E-easy Effort: easy. A task that would be a great starting point for a new contributor. C-feature Category: feature. This is adding a new feature. labels May 10, 2018
@seanmonstar
Copy link
Member

For now, the new version of hyper won't be including the typed headers directly, so I'm closing this here as a won't fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-headers Area: headers.
Projects
None yet
Development

No branches or pull requests

2 participants