-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(headers): add Range
header
#560
Conversation
Woo, thanks! I'll look this over. Also pinging @pyfisch, since he's done a ton of work on the headers. |
/// Each 'Range' header can contain one or more RangeSpecs. | ||
/// Each RangeSpec defines a range of units to fetch | ||
#[derive(PartialEq, Clone, Debug)] | ||
pub enum RangeSpec { |
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 wonder, would it work out nicely to use std::ops::{Range, RangeFrom, RangeTo}
? This could allow usage like let ranges = vec![ 0..1, 30..40];
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'm not sure if that makes sense. The thing is that Range
and RangeFrom
have their equivalent in the RangeSpec
struct, but RangeTo
doesn't. So we could implement Into<RangeSpec> for RangeTo
and for Range
, but that would leave out RangeFrom
(and RangeSpec::Last
), which IMO isn't very clean.
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.
You are right, I hadn't read the Range spec before suggesting that. I didn't realize that bytes=-500
means the last 500 bytes, I assumed it means 0-500.
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've made the same assumption when I've started implementing it ;)
Ok, so in the new commit, I've included all your suggestions regarding iterators and unnecessary allocations. I've also made some decisions regarding the TODOs: |
headers.set(Range {unit: RangeUnit::Bytes, ranges: vec![]}); | ||
|
||
assert_eq!(&headers.to_string(), "Range: bytes=\r\n"); | ||
} |
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.
mind adding the bench_header!
macro usage down here?
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.
Done.
This looks good to go. Thanks! Would you mind squashing into a single commit? The changelog only really needs to report 1 new feature: added the Range header. |
type Err = (); | ||
|
||
fn from_str(s: &str) -> Result<RangeSpec, ()> { | ||
let mut parts = s.split("-"); |
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.
You should probably use splitn(2)
here. Imagine a malformed RangeSpec
like 200-300-foobar
. It would pass as valid.
Sorry for the late comments, some are a bit nitpicky but they should help to archieve a higher conformance with the spec 😉 |
No worries. I'm glad you've reviewed the commits, as there were several things I've clearly missed reading the HTTP spec. Will do better next time! ;) |
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
Ok guys, I've made the requested changes. I wouldn't be surprised if they were unidiomatic, so let me know if that's the case. There are 2 open issues:
|
use header::{Header, HeaderFormat, RangeUnit}; | ||
use header::parsing::{from_one_raw_str, from_one_comma_delimited}; | ||
|
||
/// `Range` header, defined in [RFC7233](https://tools.ietf.org/html/rfc7233#section-3.1) |
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 docs
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
1 similar comment
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
+1 |
feat(headers): add `Range` header
Excellent work! Thanks for sticking with it. |
There are 2 TODOs left in the code. I wasn't sure what is the best way to handle these cases and I'd like to hear your feedback on that.
What I also wasn't sure about, are the names of values inside the RangeSpec enum, as well as the name of enum itself. Maybe you'll be able to come up with better ones ;)