-
-
Notifications
You must be signed in to change notification settings - Fork 192
Accept ranges #1989
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
Accept ranges #1989
Conversation
Remove unnecessary distinction between StatusCodeExcluder and StatusCodeSelector.
This change also improves error handling with invalid status code values in the lychee cache file. Below is an example with an unrepresentable status code value of 20. Previously it was converted to "Error (cached)": [http://example.com/]: [20] https://example.com/foobar | Error (cached) Now it is detected as follows: [WARN] Error while loading cache: CSV deserialize error: record 18 (line: 19, byte: 961): invalid status code value, expected the value to be >= 100 and <= 999. Continuing without.
44d09c5 to
8901e58
Compare
Previously an invalid range for --cache-exclude-status contained "failed to parse accept range" which is rather confusing.
| }; | ||
| if captures.get(2).is_none() { | ||
| return Self::new_from(start, u16::MAX); | ||
| return Self::new(start, MAX); |
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.
This is the bugfix with the 123.. example, it now ends at 999
|
@HadrienG2 & @katrinafyi feel free to take a look and review |
katrinafyi
left a comment
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.
looks very reasonable. always happy to see deduplication. miniscule comments :)
Reuse constant & document regex
| Ok(code) => { | ||
| let code = StatusCode::from_u16(code).map_err(|_| { | ||
| use serde::de::Error; | ||
| D::Error::custom( | ||
| "invalid status code value, expected the value to be >= 100 and <= 999", | ||
| ) | ||
| })?; | ||
| if code.is_success() { | ||
| // classify successful status codes as cache status success | ||
| // Does not account for status code overrides passed through | ||
| // the 'accept' flag. Instead, this is handled at a higher level | ||
| // when the cache status is converted to a status. | ||
| Ok(CacheStatus::Ok(code)) | ||
| } else { | ||
| // classify redirects, client errors, & server errors as cache status error | ||
| Ok(CacheStatus::Error(Some(code))) | ||
| } | ||
| } |
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.
Nicely done
Fixes #1769. Previously
lychee example.com --accept 123..lead toError: invalid status code.In the process I've eliminated some primitive obsession with
u16where we actually meantStatusCode. This also improved error handling with invalid values in the lychee cache file. See commit messages for more information.Improves the error messages overall. For example prviously:
error: invalid value '123..1234' for '--cache-exclude-status <CACHE_EXCLUDE_STATUS>': failed to parse accept range: no range pattern foundNow:
error: invalid value '123..1234' for '--cache-exclude-status <CACHE_EXCLUDE_STATUS>': failed to parse range: values must represent valid status codes between 100 and 999 (inclusive)