-
Notifications
You must be signed in to change notification settings - Fork 97
Description
The Range header is one of the least useful header types in this library. Most of these problems stem from the fact that it contains only a string HeaderValue, instead of a parsed representation of the Range.
-
The internal representation of range endpoints passed to
bytesand returned fromsatisfiable_rangesisBound<u64>. But this is a very poor fit, because it suggests in the return type thatBound::Excludedwould be a valid value to use in aRangeheader, when it is actually never possible for it to appear.headersshould re-introduce theByteRangeSpecenum to encode the three valid cases for theRangeheader. -
Range::bytesallows construction from a singleimpl RangeBounds<u64>.Rangeshould be extended to allow construction fromimpl Iterator<ByteRangeSpec>. -
The internal representation of a
Rangeis a string cloned from theHeaderValuepassed todecode. It should instead be a collection ofByteRanges, perhaps aSmallVec<[ByteRangeSpec; 1]>since the expected case is that there will only be one range (multipart ranges are generally uncommon).If you are constructing or parsing this header, it is expected that you are going to access the fields, so the extra memory overhead of doing so is explicitly necessary. And the type already clones the string header value! Doing the SmallVec optimization would reduce the number of allocations by 1 for the typical case.
-
satisfiable_rangesassumes the caller will know the size of the resource being fetched. It may not, in which case passingu64::MAXwill return nonsense results when a suffix range is parsed.