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

Cache control #210

Merged
merged 11 commits into from
Aug 7, 2020
Merged

Cache control #210

merged 11 commits into from
Aug 7, 2020

Conversation

yoshuawuyts
Copy link
Member

Started work on Cache-Control headers, as per https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching. I feel like caching is something that could be really interesting to get right for Tide, and probably getting the typed headers in place is the first step to experiment with building more interesting abstractions.

@yoshuawuyts yoshuawuyts marked this pull request as ready for review August 2, 2020 08:50
@yoshuawuyts yoshuawuyts mentioned this pull request Aug 2, 2020
src/cache/cache_control/cache_directive.rs Outdated Show resolved Hide resolved
src/cache/cache_control/cache_directive.rs Outdated Show resolved Hide resolved
src/cache/cache_control/cache_directive.rs Outdated Show resolved Hide resolved
src/cache/cache_control/cache_control.rs Outdated Show resolved Hide resolved
}

/// Create a new instance from headers.
pub fn from_headers(headers: impl AsRef<Headers>) -> crate::Result<Option<Self>> {
Copy link
Member

Choose a reason for hiding this comment

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

I thought from_headers() was supposed to just be Option<Self>?

And this doesn't actually seem to make use of Result?

(Although I think that in many cases Result<Option<Header>> will probably make sense but is so far inconsistent...)

Copy link
Member Author

@yoshuawuyts yoshuawuyts Aug 4, 2020

Choose a reason for hiding this comment

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

from_headers needs to be able to both detect whether a header was found, and whether parsing the header was successful. These are semantically different, and should be handled separately.

However in #99 an argument is made to use Option<Result<Self>> instead, which may actually be better. We should probably adjust all existing from_header methods to this shape, and update this one too (the only existing ones are currently behind an unstable flag, so we're okay).

Copy link
Member

@Fishrock123 Fishrock123 Aug 5, 2020

Choose a reason for hiding this comment

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

On further thought I think that Result<Option<T>> should probably always be preferred, because it allows a seamless transition to e.g. ~ -> Option<T> throws Result if that ever becomes a thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

The right signature would be -> Option<T> throws Error, but even then it'd be possible to write -> crate::Result<T> throws NoneError. I don't think the possibility of throws is something we should consider as a constraint for any design now. It's unclear if we'll ever have it, and even then the semantics are still undefined.

src/cache/cache_control/cache_control.rs Outdated Show resolved Hide resolved
Co-authored-by: Jeremiah Senkpiel <fishrock123@rocketmail.com>
}

/// Create a new instance from headers.
pub fn from_headers(headers: impl AsRef<Headers>) -> crate::Result<Option<Self>> {
Copy link
Member Author

@yoshuawuyts yoshuawuyts Aug 4, 2020

Choose a reason for hiding this comment

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

from_headers needs to be able to both detect whether a header was found, and whether parsing the header was successful. These are semantically different, and should be handled separately.

However in #99 an argument is made to use Option<Result<Self>> instead, which may actually be better. We should probably adjust all existing from_header methods to this shape, and update this one too (the only existing ones are currently behind an unstable flag, so we're okay).

src/cache/cache_control/cache_directive.rs Outdated Show resolved Hide resolved
src/cache/cache_control/cache_directive.rs Outdated Show resolved Hide resolved
@yoshuawuyts
Copy link
Member Author

yoshuawuyts commented Aug 7, 2020

Going to merge this + the other PRs, and then do a pass in a separate PR to convert Result<Option<Self>> to Option<Result<Self>>.

edit: coming around on that idea; implemented this for several instances of from_headers and it doesn't feel right. Ah well, fewer breaking changes.

@yoshuawuyts yoshuawuyts merged commit 7b0a1b3 into master Aug 7, 2020
@yoshuawuyts yoshuawuyts deleted the cache-control branch August 7, 2020 14:55
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.

2 participants