Skip to main content

parse_range_header

Function parse_range_header 

Source
pub fn parse_range_header(
    range: &str,
    content_length: u64,
) -> Result<(u64, u64), S3ServiceError>
Expand description

Parse an HTTP Range header value and return the inclusive byte range.

Supported formats:

  • bytes=0-499 – first 500 bytes
  • bytes=-500 – last 500 bytes
  • bytes=500- – from byte 500 to the end
  • bytes=0- – the entire content

Returns an inclusive (start, end) tuple.

§Errors

Returns S3ServiceError::InvalidRange if the range header is malformed or specifies an unsatisfiable range.

§Examples

use rustack_s3_core::utils::parse_range_header;

let (start, end) = parse_range_header("bytes=0-499", 1000).unwrap();
assert_eq!((start, end), (0, 499));