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
chore: apply small refactoring #1715
Conversation
79e69cd
to
e44b59c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I really appreciate cleanups like this! A couple small comments to make sure the behavior is correct.
Separately, is there a way we can confirm the value that we're writing is parseable by httpdate
? While the current approach is convoluted, it is making sure to compare apples to apples by using the Expires
struct directly for the comparison.
It actually looks like the Expires
header provides an implementation of From<Expires> for SystemTime
, so we might be able access the time directly, rather than needing to parse the string value.
Another important piece is we want to make sure any comparison is backwards-compatible with the existing expiry file.
crates/archive/src/lib.rs
Outdated
@@ -18,7 +18,7 @@ pub enum ArchiveError { | |||
HttpError(attohttpc::StatusCode), | |||
|
|||
#[error("HTTP header '{0}' not found")] | |||
MissingHeaderError(String), | |||
MissingHeaderError(attohttpc::header::HeaderName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the Header::name
associated function returns a &'static
reference to the HeaderName
object. Given that, we can probably use the same here (&'static HeaderName
) instead of needing to convert it to an owned value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use &'static HeaderName
.
.is_some_and(|expiry_date| SystemTime::now() < expiry_date) | ||
{ | ||
return Ok(None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's definitely possible I'm misreading, but I believe this might be inverting the condition. In the current code, when SystemTime::now() < expiry_date
, then we read the cached file. However, in this one we're returning no cache with that same condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think the behavior would be the same as the code before this change as the negation of this condition is evaluated.
e44b59c
to
c3c1191
Compare
As
Yes. When using
Since |
c3c1191
to
737a2ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Applies small refactoring.