Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 #![warn(clippy::pedantic)]
2 #![allow(clippy::uninlined_format_args)]
3 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::{Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#};
4 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#;
5
6 const UNIT_SEPrust-analyzer cargo http-range-header 0.4.2 UNIT_SEP.: &str = "bytes=";
7 /// Function that parses the content of a range header.
8 ///
9 /// Follows the [spec here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range)
10 ///
11 /// And [here](https://www.ietf.org/rfc/rfc2616.txt)
12 ///
13 /// Will only accept bytes ranges, will update when [this spec](https://www.iana.org/assignments/http-parameters/http-parameters.xhtml) changes to allow other units.
14 ///
15 /// Parses ranges strictly, as in the examples contained in the above specifications.
16 ///
17 /// Ranges such as `bytes=0-15, 16-20, abc` will be rejected immediately.
18 ///
19 /// It preserves the range ordering, the specification leaves it open to the server to determine whether
20 /// ranges that are out of order are correct or not, ie `bytes=20-30, 0-15`
21 ///
22 /// # Example no trailing or leading whitespaces
23 /// ```
24 /// // Ok
25 /// assert!(http_range_header::parse_range_header("bytes=0-15").is_ok());
26 /// // Not allowed
27 /// assert!(http_range_header::parse_range_header("bytes=0-15 ").is_err());
28 /// // Also not allowed
29 /// assert!(http_range_header::parse_range_header("bytes= 0-15").is_err());
30 /// ```
31 ///
32 /// # Example No leading whitespaces except in the case of separating multipart ranges
33 /// ```
34 /// // Ok, multipart with a leading whitespace after comma
35 /// assert!(http_range_header::parse_range_header("bytes=0-15, 20-30").is_ok());
36 /// // Ok multipart without leading whitespace after comma
37 /// assert!(http_range_header::parse_range_header("bytes=0-15,20-30").is_ok());
38 /// ```
39 ///
40 /// # Example No negative values, no leading zeroes, no plus-sign
41 /// ```
42 /// // No negatives
43 /// assert!(http_range_header::parse_range_header("bytes=-12-15").is_err());
44 /// // No leading zeroes
45 /// assert!(http_range_header::parse_range_header("bytes=00-15").is_err());
46 /// // No plus sign
47 /// assert!(http_range_header::parse_range_header("bytes=+0-15").is_err());
48 /// ```
49 ///
50 /// Makes two passes and parses ranges strictly. On the first pass, if any range is malformed returns an `Err`.
51 ///
52 /// On the second pass if the ranges doesn't make sense (reversed range, range out of bounds, etc.) returns an `Err`.
53 /// # Example with a standard valid range
54 ///
55 /// ```
56 /// let input = "bytes=0-15";
57 /// let file_size_bytes = 512;
58 /// let parsed_ranges = http_range_header::parse_range_header(input);
59 ///
60 /// match parsed_ranges {
61 /// Ok(ranges) => {
62 /// match ranges.validate(file_size_bytes) {
63 /// Ok(valid_ranges) => {
64 /// for range in valid_ranges {
65 /// // do something with ranges
66 /// assert_eq!(0..=15, range)
67 /// }
68 /// }
69 /// Err(_err) => {
70 /// // Do something when ranges doesn't make sense
71 /// panic!("Weird range!")
72 /// }
73 /// }
74 /// }
75 /// Err(_err) => {
76 /// // Do something with malformed ranges
77 /// panic!("Malformed range!")
78 /// }
79 /// }
80 /// ```
81 ///
82 /// The parser makes two passes, one without a known file-size, ensuring all ranges are syntactically correct.
83 /// The returned struct will through its `validate` method accept a file-size and figure out whether or not the
84 /// syntactically correct ranges actually makes sense in context
85 ///
86 /// The range `bytes=0-20` on a file with 15 bytes will be accepted in the first pass as the content size is unknown.
87 /// On the second pass (`validate`) it will be truncated to `file_size - 1` as per [the spec](https://httpwg.org/specs/rfc9110.html#rfc.section.14.1.2).
88 /// # Example range truncates in `validate` because it exceedes
89 /// ```
90 /// let input = "bytes=0-20";
91 /// let file_size_bytes = 15;
92 /// let parsed_ranges = http_range_header::parse_range_header(input)
93 /// // Is syntactically correct
94 /// .unwrap();
95 /// let validated = parsed_ranges.validate(file_size_bytes).unwrap();
96 /// assert_eq!(vec![0..=14], validated);
97 /// ```
98 ///
99 /// Range reversal and overlap is also checked in the second pass, the range `bytes=0-20, 5-10`
100 /// will become two syntactically correct ranges, but `validate` will return ann `Err`.
101 ///
102 /// This is an opinionated implementation, [the spec](https://datatracker.ietf.org/doc/html/rfc7233)
103 /// allows a server to determine its implementation of overlapping ranges, this api currently does not allow it.
104 ///
105 /// # Example multipart-range fails `validate` because of an overlap
106 /// ```
107 /// let input = "bytes=0-15, 10-20, 30-50";
108 /// let file_size_bytes = 512;
109 /// let parsed_ranges = http_range_header::parse_range_header(input)
110 /// // Is syntactically correct
111 /// .unwrap();
112 /// let validated = parsed_ranges.validate(file_size_bytes);
113 /// // Some ranges overlap, all valid ranges get truncated to 1 Err
114 /// assert!(validated.is_err());
115 /// ```
116 /// # Errors
117 /// Will return an error if the `range_header_value` cannot be strictly parsed into a range
118 /// per the http spec.
119 pub fn parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(
120 range_header_value: &str,
121 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ParsedRangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#> {
122 const COMMArust-analyzer cargo http-range-header 0.4.2 COMMA.: char = ',';
123 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((prefix, indicated_range)) = range_header_value.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().(UNIT_SEPrust-analyzer cargo http-range-header 0.4.2 UNIT_SEP.) {
124 if indicated_range.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(char::is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().) {
125 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::StartsWithWhitespacerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#StartsWithWhitespace#);
126 }
127 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().prefix.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
128 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::DoesNotStartWithTokenrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#DoesNotStartWithToken#);
129 }
130 let mut last_err = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
131 let ranges = indicated_range
132 .splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(COMMArust-analyzer cargo http-range-header 0.4.2 COMMA.)
133 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|range| {
134 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(trimmed) = trimrust-analyzer cargo http-range-header 0.4.2 trim().(range) {
135 match parse_innerrust-analyzer cargo http-range-header 0.4.2 parse_inner().(trimmed) {
136 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(parsed) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parsed),
137 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
138 last_err = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e);
139 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
140 }
141 }
142 } else {
143 last_err = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::IllegalWhitespacerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#IllegalWhitespace#);
144 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
145 }
146 })
147 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#>>();
148 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last_err) = last_err {
149 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(last_err);
150 }
151 if ranges.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
152 // Some other error should have been caught before we end up here
153 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::Emptyrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#Empty#)
154 } else {
155 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ParsedRangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#::newrust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]new().(ranges))
156 }
157 } else {
158 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::DoesNotStartWithTokenrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#DoesNotStartWithToken#)
159 }
160 }
161
162 fn trimrust-analyzer cargo http-range-header 0.4.2 trim().(s: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> {
163 if s.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(char::is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().) || s.match_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]match_indices().(char::is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 {
164 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
165 } else {
166 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().())
167 }
168 }
169
170 #[inline]
171 fn parse_innerrust-analyzer cargo http-range-header 0.4.2 parse_inner().(range: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#> {
172 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((start, end)) = range.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('-') {
173 if start.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
174 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(end) = strict_parse_u64rust-analyzer cargo http-range-header 0.4.2 strict_parse_u64().(end) {
175 if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 {
176 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::ZeroSuffixrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#ZeroSuffix#);
177 }
178 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(
179 StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::FromLastrust-analyzer cargo http-range-header 0.4.2 StartPosition#FromLast#(end),
180 EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#,
181 ));
182 }
183 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadEndOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadEndOfRange#);
184 }
185 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start) = strict_parse_u64rust-analyzer cargo http-range-header 0.4.2 strict_parse_u64().(start) {
186 if end.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
187 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(
188 StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(start),
189 EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#,
190 ));
191 }
192 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(end) = strict_parse_u64rust-analyzer cargo http-range-header 0.4.2 strict_parse_u64().(end) {
193 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(
194 StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(start),
195 EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(end),
196 ));
197 }
198 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadEndOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadEndOfRange#);
199 }
200 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadStartOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadStartOfRange#);
201 }
202 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::UnexpectedNumberOfDashesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#UnexpectedNumberOfDashes#)
203 }
204
205 fn strict_parse_u64rust-analyzer cargo http-range-header 0.4.2 strict_parse_u64().(s: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64> {
206 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('+') && (s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('0')) {
207 return s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<u64>().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
208 }
209 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
210 }
211
212 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
213 pub struct ParsedRangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges# {
214 pub rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#>,
215 }
216
217 impl ParsedRangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges# {
218 fn newrust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]new().(ranges: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#>) -> Selfrust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges] {
219 ParsedRangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges# { rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges. }
220 }
221
222 /// Validates a parsed range for a given file-size in bytes.
223 /// # Errors
224 /// If the range is invalid for the the file-size.
225 pub fn validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(
226 &self,
227 file_size_bytes: u64,
228 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<u64>>, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#> {
229 let len = self.rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
230 let mut validated = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(len);
231 for parsed in &self.rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges. {
232 let start = match parsed.startrust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#start. {
233 StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(i) => i,
234 StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::FromLastrust-analyzer cargo http-range-header 0.4.2 StartPosition#FromLast#(i) => {
235 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().file_size_bytes {
236 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::FileSuffixOutOfBoundsrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#FileSuffixOutOfBounds#);
237 }
238 file_size_bytes.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(i)
239 }
240 };
241 let end = match parsed.endrust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#end. {
242 EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(i) => corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(i, file_size_bytes.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(1)),
243 EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte# => file_size_bytes.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(1),
244 };
245
246 let valid = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(start, end);
247 validated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(valid);
248 }
249 // False positive
250 #[allow(clippy::match_same_arms)]
251 match validate_rangesrust-analyzer cargo http-range-header 0.4.2 validate_ranges().(validated.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()) {
252 RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#::Validrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Valid# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(validated),
253 RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#::Overlappingrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Overlapping# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#),
254 RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#::Reversedrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Reversed# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::RangeReversedrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#RangeReversed#),
255 }
256 }
257 }
258
259 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
260 pub enum RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError# {
261 OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#,
262 RangeReversedrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#RangeReversed#,
263 FileSuffixOutOfBoundsrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#FileSuffixOutOfBounds#,
264 IllegalWhitespacerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#IllegalWhitespace#,
265 StartsWithWhitespacerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#StartsWithWhitespace#,
266 DoesNotStartWithTokenrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#DoesNotStartWithToken#,
267 ZeroSuffixrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#ZeroSuffix#,
268 BadStartOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadStartOfRange#,
269 BadEndOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadEndOfRange#,
270 UnexpectedNumberOfDashesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#UnexpectedNumberOfDashes#,
271 Emptyrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#Empty#,
272 }
273
274 impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError# {
275 fn fmtrust-analyzer cargo http-range-header 0.4.2 impl#[RangeUnsatisfiableError][Display]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
276 match self {
277 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges# => {
278 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("RangeUnsatisfiable: Ranges overlap")
279 }
280 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::RangeReversedrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#RangeReversed# => {
281 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("RangeUnsatisfiable: Reversed range")
282 }
283 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::FileSuffixOutOfBoundsrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#FileSuffixOutOfBounds# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(
284 "RangeUnsatisfiable: File suffix out of bounds (larger than file bytes)",
285 ),
286 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::IllegalWhitespacerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#IllegalWhitespace# => {
287 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("RangeUnsatisfiable: Illegal whitespaces in range")
288 }
289 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::StartsWithWhitespacerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#StartsWithWhitespace# => {
290 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("RangeUnsatisfiable: Range starts with whitespace")
291 }
292 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::DoesNotStartWithTokenrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#DoesNotStartWithToken# => f.write_fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_fmt().(format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!(
293 "RangeUnsatisfiable: Range does not start with token '{UNIT_SEP}'"
294 )),
295 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::ZeroSuffixrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#ZeroSuffix# => {
296 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("RangeUnsatisfiable: Range ends at 0")
297 }
298 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadStartOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadStartOfRange# => {
299 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("RangeUnsatisfiable: Unparseable start of range")
300 }
301 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadEndOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadEndOfRange# => {
302 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("RangeUnsatisfiable: Unparseable end of range")
303 }
304 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::UnexpectedNumberOfDashesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#UnexpectedNumberOfDashes# => {
305 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("RangeUnsatisfiable: Unexpected number of dashes")
306 }
307 RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::Emptyrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#Empty# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(
308 "RangeUnsatisfiable: Failed to parse range fallback error, please file an issue",
309 ),
310 }
311 }
312 }
313
314 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError# {}
315
316 enum RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult# {
317 Validrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Valid#,
318 Overlappingrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Overlapping#,
319 Reversedrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Reversed#,
320 }
321
322 fn validate_rangesrust-analyzer cargo http-range-header 0.4.2 validate_ranges().(ranges: &[RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#<u64>]) -> RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult# {
323 let mut bounds = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
324 for range in ranges {
325 let start = range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().();
326 let end = range.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().();
327 if start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().end {
328 return RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#::Reversedrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Reversed#;
329 } else if ranges.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 {
330 return RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#::Validrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Valid#;
331 }
332 bounds.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]start().(), range.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]end().()));
333 }
334 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#bounds.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
335 for j in i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#bounds.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
336 if bounds[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().bounds[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().j]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..1 && bounds[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().j]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().bounds[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..1 {
337 return RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#::Overlappingrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Overlapping#;
338 }
339 }
340 }
341 RangeValidationResultrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#::Validrust-analyzer cargo http-range-header 0.4.2 RangeValidationResult#Valid#
342 }
343
344 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
345 pub struct SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange# {
346 pub startrust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#start.: StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#,
347 pub endrust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#end.: EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#,
348 }
349
350 impl SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange# {
351 fn newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(start: StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#, end: EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#) -> Selfrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange] {
352 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange# { startrust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#start., endrust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#end. }
353 }
354 }
355
356 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
357 pub enum StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition# {
358 Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(u64),
359 FromLastrust-analyzer cargo http-range-header 0.4.2 StartPosition#FromLast#(u64),
360 }
361
362 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
363 pub enum EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition# {
364 Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(u64),
365 LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#,
366 }
367
368 #[cfg(test)]
369 mod testsrust-analyzer cargo http-range-header 0.4.2 tests/ {
370 use craterust-analyzer cargo http-range-header 0.4.2 crate/::{
371 parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header()., EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#, ParsedRangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#, StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#,
372 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#,
373 };
374 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#;
375
376 const TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.: u64 = 10_000;
377 /// Testing standard range compliance against <https://datatracker.ietf.org/doc/html/rfc7233>
378 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
379 fn rfc_7233_standard_test1rust-analyzer cargo http-range-header 0.4.2 tests/rfc_7233_standard_test1().() {
380 let input = "bytes=0-499";
381 let expect =
382 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(499));
383 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
384 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(single_rangerust-analyzer cargo http-range-header 0.4.2 tests/single_range().(expect), actual);
385 let expect = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(0, 499);
386 let actual = actual.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`][Clone]clone().();
387 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
388 }
389
390 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
391 fn rfc_7233_standard_test2rust-analyzer cargo http-range-header 0.4.2 tests/rfc_7233_standard_test2().() {
392 let input = "bytes=500-999";
393 let expect =
394 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(500), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(999));
395 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
396 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(single_rangerust-analyzer cargo http-range-header 0.4.2 tests/single_range().(expect), actual);
397 let expect = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(500, 999);
398 let actual = actual.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`][Clone]clone().();
399 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
400 }
401
402 /// Testing suffix compliance against <https://datatracker.ietf.org/doc/html/rfc7233>
403 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
404 fn rfc_7233_suffixed_testrust-analyzer cargo http-range-header 0.4.2 tests/rfc_7233_suffixed_test().() {
405 let input = "bytes=-500";
406 let expect =
407 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::FromLastrust-analyzer cargo http-range-header 0.4.2 StartPosition#FromLast#(500), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#);
408 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
409 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(single_rangerust-analyzer cargo http-range-header 0.4.2 tests/single_range().(expect), actual);
410 let expect = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(9500, 9999);
411 let actual = actual.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(10_000).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`][Clone]clone().();
412 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
413 }
414
415 /// Testing open range compliance against <https://datatracker.ietf.org/doc/html/rfc7233>
416 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
417 fn rfc_7233_open_range_testrust-analyzer cargo http-range-header 0.4.2 tests/rfc_7233_open_range_test().() {
418 let input = "bytes=9500-";
419 let expect =
420 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(9500), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#);
421 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
422 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(single_rangerust-analyzer cargo http-range-header 0.4.2 tests/single_range().(expect), actual);
423 let expect = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(9500, 9999);
424 let actual = actual.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(10_000).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`][Clone]clone().();
425 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
426 }
427
428 /// Testing first and last bytes compliance against <https://datatracker.ietf.org/doc/html/rfc7233>
429 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
430 fn rfc_7233_first_and_lastrust-analyzer cargo http-range-header 0.4.2 tests/rfc_7233_first_and_last().() {
431 let input = "bytes=0-0, -1";
432 let expect = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
433 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(0)),
434 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::FromLastrust-analyzer cargo http-range-header 0.4.2 StartPosition#FromLast#(1), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#),
435 ];
436 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
437 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual.rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges.);
438 let expect = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0..=0, 9999..=9999];
439 let actual = actual.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(10_000).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
440 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
441 }
442
443 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
444 fn parse_standard_rangerust-analyzer cargo http-range-header 0.4.2 tests/parse_standard_range().() {
445 let input = "bytes=0-1023";
446 let expect =
447 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(1023));
448 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
449 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(single_rangerust-analyzer cargo http-range-header 0.4.2 tests/single_range().(expect), actual);
450 let expect = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(0, 1023);
451 let actual = actual.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`][Clone]clone().();
452 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
453 }
454
455 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
456 fn parse_open_ended_rangerust-analyzer cargo http-range-header 0.4.2 tests/parse_open_ended_range().() {
457 let input = "bytes=0-";
458 let expect = SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#);
459 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
460 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(single_rangerust-analyzer cargo http-range-header 0.4.2 tests/single_range().(expect), actual);
461 let expect = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(0, TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().1);
462 let actual = actual.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`][Clone]clone().();
463 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
464 }
465
466 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
467 fn parse_suffix_range_edgerust-analyzer cargo http-range-header 0.4.2 tests/parse_suffix_range_edge().() {
468 let input = &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("bytes=-{}", TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.);
469 let expect = SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(
470 StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::FromLastrust-analyzer cargo http-range-header 0.4.2 StartPosition#FromLast#(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.),
471 EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#,
472 );
473 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
474 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(single_rangerust-analyzer cargo http-range-header 0.4.2 tests/single_range().(expect), actual);
475 let expect = RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(0, TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().1);
476 let actual = actual.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`][Clone]clone().();
477 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
478 }
479
480 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
481 fn parse_empty_as_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_empty_as_invalid().() {
482 let input = "";
483 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
484 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::DoesNotStartWithTokenrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#DoesNotStartWithToken#));
485 }
486
487 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
488 fn parse_empty_range_as_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_empty_range_as_invalid().() {
489 let input = "bytes=";
490 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
491 // 0 is unexpected
492 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
493 parsed,
494 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::UnexpectedNumberOfDashesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#UnexpectedNumberOfDashes#)
495 );
496 }
497
498 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
499 fn parse_range_starting_with_whitespace_as_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_range_starting_with_whitespace_as_invalid().() {
500 let input = "bytes= 0-15";
501 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
502 // 0 is unexpected
503 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::StartsWithWhitespacerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#StartsWithWhitespace#));
504 }
505
506 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
507 fn parse_range_token_starting_with_whitespace_as_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_range_token_starting_with_whitespace_as_invalid().() {
508 let input = " bytes=0-15";
509 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
510 // 0 is unexpected
511 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::DoesNotStartWithTokenrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#DoesNotStartWithToken#));
512 }
513
514 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
515 fn parse_range_strict_parse_numericalrust-analyzer cargo http-range-header 0.4.2 tests/parse_range_strict_parse_numerical().() {
516 let input = "bytes=+0-15";
517 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
518 // 0 is unexpected
519 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadStartOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadStartOfRange#));
520 }
521
522 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
523 fn parse_bad_unit_as_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_bad_unit_as_invalid().() {
524 let input = "abcde=0-10";
525 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
526 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::DoesNotStartWithTokenrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#DoesNotStartWithToken#));
527 }
528
529 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
530 fn parse_missing_equals_as_malformedrust-analyzer cargo http-range-header 0.4.2 tests/parse_missing_equals_as_malformed().() {
531 let input = "bytes0-10";
532 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
533 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::DoesNotStartWithTokenrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#DoesNotStartWithToken#));
534 }
535
536 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
537 fn parse_negative_bad_characters_in_range_as_malformedrust-analyzer cargo http-range-header 0.4.2 tests/parse_negative_bad_characters_in_range_as_malformed().() {
538 let input = "bytes=1-10a";
539 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
540 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadEndOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadEndOfRange#));
541 }
542
543 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
544 fn parse_negative_numbers_as_malformedrust-analyzer cargo http-range-header 0.4.2 tests/parse_negative_numbers_as_malformed().() {
545 let input = "bytes=-1-10";
546 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
547 // Becomes bad eor, since -1 signals suffixed range
548 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadEndOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadEndOfRange#));
549 }
550
551 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
552 fn parse_bad_characters_in_start_of_rangerust-analyzer cargo http-range-header 0.4.2 tests/parse_bad_characters_in_start_of_range().() {
553 let input = "bytes=a1-10";
554 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
555 // Becomes bad eor, since -1 signals suffixed range
556 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::BadStartOfRangerust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#BadStartOfRange#));
557 }
558
559 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
560 fn parse_out_of_bounds_overrun_as_content_lengthrust-analyzer cargo http-range-header 0.4.2 tests/parse_out_of_bounds_overrun_as_content_length().() {
561 let input = &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("bytes=0-{}", TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.);
562 let expect = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![RangeInclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]new().(0, TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH. -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). 1)];
563 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input)
564 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
565 .validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.)
566 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
567 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expect, actual);
568 }
569
570 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
571 fn parse_out_of_bounds_suffix_overrun_as_unsatisfiablerust-analyzer cargo http-range-header 0.4.2 tests/parse_out_of_bounds_suffix_overrun_as_unsatisfiable().() {
572 let input = &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("bytes=-{}", TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1);
573 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input)
574 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
575 .validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.);
576 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::FileSuffixOutOfBoundsrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#FileSuffixOutOfBounds#));
577 }
578
579 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
580 fn parse_zero_length_suffix_as_unsatisfiablerust-analyzer cargo http-range-header 0.4.2 tests/parse_zero_length_suffix_as_unsatisfiable().() {
581 let input = "bytes=-0";
582 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
583 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::ZeroSuffixrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#ZeroSuffix#));
584 }
585
586 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
587 fn parse_single_reversed_as_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_single_reversed_as_invalid().() {
588 let input = "bytes=15-0";
589 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
590 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
591 parsed.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.),
592 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::RangeReversedrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#RangeReversed#)
593 );
594 }
595
596 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
597 fn parse_zero_range_as_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_zero_range_as_invalid().() {
598 let input = "bytes=15-";
599 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
600 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
601 parsed.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(0),
602 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::RangeReversedrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#RangeReversed#)
603 );
604 }
605
606 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
607 fn parse_zero_range_last_byte_valid_if_file_size_0rust-analyzer cargo http-range-header 0.4.2 tests/parse_zero_range_last_byte_valid_if_file_size_0().() {
608 let input = "bytes=0-";
609 let expect = SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#);
610 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
611 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual, expect);
612 }
613
614 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
615 fn parse_zero_range_closed_valid_if_file_size_0rust-analyzer cargo http-range-header 0.4.2 tests/parse_zero_range_closed_valid_if_file_size_0().() {
616 let input = "bytes=0-0";
617 let expect = SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(0));
618 let actual = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
619 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual, expect);
620 }
621
622 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
623 fn parse_multi_rangerust-analyzer cargo http-range-header 0.4.2 tests/parse_multi_range().() {
624 let input = "bytes=0-1023, 2015-3000, 4000-4500, 8000-9999";
625 let expected_ranges = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
626 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(1023)),
627 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(2015), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(3000)),
628 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(4000), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(4500)),
629 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(8000), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(9999)),
630 ];
631 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
632 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected_ranges, parsed.rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges.);
633 let validated = parsed.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
634 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
635 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0..=1023, 2015..=3000, 4000..=4500, 8000..=9999],
636 validated
637 );
638 }
639
640 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
641 fn parse_multi_range_with_openrust-analyzer cargo http-range-header 0.4.2 tests/parse_multi_range_with_open().() {
642 let input = "bytes=0-1023, 1024-";
643 let expected_ranges = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
644 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(1023)),
645 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(1024), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#),
646 ];
647 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
648 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected_ranges, parsed.rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges.);
649 let validated = parsed.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
650 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0..=1023, 1024..=9999], validated);
651 }
652
653 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
654 fn parse_multi_range_with_suffixrust-analyzer cargo http-range-header 0.4.2 tests/parse_multi_range_with_suffix().() {
655 let input = "bytes=0-1023, -1000";
656 let expected_ranges = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
657 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 StartPosition#Index#(0), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::Indexrust-analyzer cargo http-range-header 0.4.2 EndPosition#Index#(1023)),
658 SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#::newrust-analyzer cargo http-range-header 0.4.2 impl#[SyntacticallyCorrectRange]new().(StartPositionrust-analyzer cargo http-range-header 0.4.2 StartPosition#::FromLastrust-analyzer cargo http-range-header 0.4.2 StartPosition#FromLast#(1000), EndPositionrust-analyzer cargo http-range-header 0.4.2 EndPosition#::LastByterust-analyzer cargo http-range-header 0.4.2 EndPosition#LastByte#),
659 ];
660 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
661 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected_ranges, parsed.rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges.);
662 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected_ranges, parsed.rangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#ranges.);
663 let validated = parsed.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
664 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0..=1023, 9000..=9999], validated);
665 }
666
667 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
668 fn parse_overlapping_multi_range_as_unsatisfiable_standardrust-analyzer cargo http-range-header 0.4.2 tests/parse_overlapping_multi_range_as_unsatisfiable_standard().() {
669 let input = "bytes=0-1023, 500-800";
670 assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#);
671 let input = "bytes=0-0, 0-15";
672 assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#);
673 let input = "bytes=0-20, 20-35";
674 assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#);
675 }
676
677 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
678 fn parse_overlapping_multi_range_as_unsatisfiable_openrust-analyzer cargo http-range-header 0.4.2 tests/parse_overlapping_multi_range_as_unsatisfiable_open().() {
679 let input = "bytes=0-, 5000-6000";
680 assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#);
681 }
682
683 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
684 fn parse_overlapping_multi_range_as_unsatisfiable_suffixedrust-analyzer cargo http-range-header 0.4.2 tests/parse_overlapping_multi_range_as_unsatisfiable_suffixed().() {
685 let input = "bytes=8000-9000, -1001";
686 assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#);
687 let input = "bytes=8000-9000, -1000";
688 assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#);
689 // This doesn't overlap
690 let input = "bytes=8000-9000, -999";
691 parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input)
692 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
693 .validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.)
694 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
695 }
696
697 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
698 fn parse_overlapping_multi_range_as_unsatisfiable_suffixed_openrust-analyzer cargo http-range-header 0.4.2 tests/parse_overlapping_multi_range_as_unsatisfiable_suffixed_open().() {
699 let input = "bytes=0-, -1";
700 assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::OverlappingRangesrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#OverlappingRanges#);
701 }
702
703 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
704 fn parse_multi_range_with_a_reversed_as_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_multi_range_with_a_reversed_as_invalid().() {
705 let input = "bytes=0-15, 30-20";
706 assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input, RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#::RangeReversedrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#RangeReversed#);
707 }
708
709 fn assert_validation_errrust-analyzer cargo http-range-header 0.4.2 tests/assert_validation_err().(input: &str, err: RangeUnsatisfiableErrorrust-analyzer cargo http-range-header 0.4.2 RangeUnsatisfiableError#) {
710 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input)
711 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
712 .validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(TEST_FILE_LENGTHrust-analyzer cargo http-range-header 0.4.2 tests/TEST_FILE_LENGTH.);
713 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err), parsed);
714 }
715
716 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
717 fn parse_multi_range_rejects_invalidrust-analyzer cargo http-range-header 0.4.2 tests/parse_multi_range_rejects_invalid().() {
718 let input = "bytes=0-15, 25, 9, ";
719 let parsed = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(input);
720 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
721 }
722
723 #[quickcheck_macrosrust-analyzer cargo quickcheck_macros 1.2.0 crate/::quickcheckrust-analyzer cargo quickcheck_macros 1.2.0 quickcheck:]
724 #[allow(clippy::needless_pass_by_value)]
725 fn always_errs_on_random_inputrust-analyzer cargo http-range-header 0.4.2 tests/always_errs_on_random_input().(input: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> quickcheckrust-analyzer cargo quickcheck 1.1.0 crate/::TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult# {
726 // Basic regex matching most valid range headers
727 let acceptable = regexrust-analyzer cargo regex 1.13.1 crate/::Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#::newrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]new().(
728 "^bytes=((\\d+-\\d+,\\s?)|(\\d+-,\\s?)|(-\\d+,\\s?))*((\\d+-\\d+)|(\\d+-)|(-\\d+))+$",
729 )
730 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
731 if acceptable.is_matchrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]is_match().(&input) {
732 quickcheckrust-analyzer cargo quickcheck 1.1.0 crate/::TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult#::discardrust-analyzer cargo quickcheck 1.1.0 tester/impl#[TestResult]discard().()
733 } else if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(passed_first_pass) = parse_range_headerrust-analyzer cargo http-range-header 0.4.2 parse_range_header().(&input) {
734 quickcheckrust-analyzer cargo quickcheck 1.1.0 crate/::TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult#::from_boolrust-analyzer cargo quickcheck 1.1.0 tester/impl#[TestResult]from_bool().(passed_first_pass.validaterust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]validate().(u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX.).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().())
735 } else {
736 quickcheckrust-analyzer cargo quickcheck 1.1.0 crate/::TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult#::passedrust-analyzer cargo quickcheck 1.1.0 tester/impl#[TestResult]passed().()
737 }
738 }
739
740 fn single_rangerust-analyzer cargo http-range-header 0.4.2 tests/single_range().(syntactically_correct: SyntacticallyCorrectRangerust-analyzer cargo http-range-header 0.4.2 SyntacticallyCorrectRange#) -> ParsedRangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges# {
741 ParsedRangesrust-analyzer cargo http-range-header 0.4.2 ParsedRanges#::newrust-analyzer cargo http-range-header 0.4.2 impl#[ParsedRanges]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![syntactically_correct])
742 }
743 }