volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
10.98k stars 230 forks source link

chore: apply small refactoring #1715

Closed tottoto closed 4 months ago

tottoto commented 6 months ago

Applies small refactoring.

tottoto commented 6 months ago

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.

As headers::Expires and httpdate both support HTTP-date format defined in rfc7231, they are compatible.

It actually looks like the Expires header provides an implementation of From for SystemTime, so we might be able access the time directly, rather than needing to parse the string value.

Yes. When using Expires, it is possible to evaluate like this SystemTime::now() < expiry_date.into().

Another important piece is we want to make sure any comparison is backwards-compatible with the existing expiry file.

Since headers crate actually uses httpdate to parse and format date and delegate the comparison to internal httpdate implementation, and the httpdate uses SystemTime for its comparison, it behaves exactly the same.