{"record":{"id":"81996711dfc44daf","repo":"ducaale/xh","slug":"invalid-content-range","errorCode":null,"errorMessage":"Invalid Content-Range: {:?}","messagePattern":"Invalid Content-Range: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/download.rs","lineNumber":143,"sourceCode":"        .context(\"Can't parse Content-Range first_byte_pos\")?;\n    let last_byte_pos: u64 = caps\n        .name(\"last_byte_pos\")\n        .unwrap()\n        .as_str()\n        .parse()\n        .context(\"Can't parse Content-Range last_byte_pos\")?;\n    let complete_length: Option<u64> = caps\n        .name(\"complete_length\")\n        .map(|num| {\n            num.as_str()\n                .parse()\n                .context(\"Can't parse Content-Range complete_length\")\n        })\n        .transpose()?;\n    // Note that last_byte_pos must be strictly less than complete_length\n    // If first_byte_pos == last_byte_pos exactly one byte is sent\n    if first_byte_pos > last_byte_pos {\n        return Err(anyhow!(\"Invalid Content-Range: {:?}\", header));\n    }\n    if let Some(complete_length) = complete_length {\n        if last_byte_pos >= complete_length {\n            return Err(anyhow!(\"Invalid Content-Range: {:?}\", header));\n        }\n        if complete_length != last_byte_pos + 1 {\n            return Err(anyhow!(\"Content-Range has wrong end: {:?}\", header));\n        }\n    }\n    if expected_start != first_byte_pos {\n        return Err(anyhow!(\"Content-Range has wrong start: {:?}\", header));\n    }\n    Ok(last_byte_pos + 1)\n}\n\nconst BAR_TEMPLATE: &str =\n    \"{spinner:.green} {percent}% [{wide_bar:.cyan/blue}] {bytes} {bytes_per_sec} ETA {eta}\";\nconst UNCOLORED_BAR_TEMPLATE: &str =","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/download.rs#L125-L161","documentation":"After parsing first_byte_pos, last_byte_pos and optional complete_length out of Content-Range, the tool validates them. This error fires when the header is internally inconsistent: the last byte position precedes the first (first_byte_pos > last_byte_pos), or a supplied complete_length is not greater than last_byte_pos.","triggerScenarios":"Server sends e.g. 'bytes 500-100/1000' where 100 < 500, or 'bytes 0-999/500' where complete_length (500) <= last_byte_pos (999).","commonSituations":"Buggy download servers computing range arithmetic wrong, caching layers serving mismatched partial content, resume offset out of sync with the file size on the server.","solutions":["Delete the partially downloaded file and restart the download from byte 0","Verify the server's Content-Range arithmetic with a manual ranged request (curl -r) and fix/upgrade the server if inconsistent","Disable resume/partial downloads for this host if it's known to emit broken ranges"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn content_range_sane(first: u64, last: u64, total: Option<u64>) -> bool {\n    first <= last && total.map_or(true, |t| last < t)\n}","typeGuard":null,"tryCatchPattern":"match total_for_content_range(header, expected_start) {\n    Ok(total) => resume_from(expected_start, total),\n    Err(e) if e.to_string().contains(\"Invalid Content-Range\") => {\n        eprintln!(\"Server sent inconsistent Content-Range; restarting from scratch\");\n        delete_partial_and_restart();\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Delete the partial file instead of resuming when the server misbehaves","Verify ranged requests manually with curl -r before scripting resumes","Watch for server-side file changes between initial and resume requests"],"tags":["http","download","content-range","validation","rust"],"backgroundTag":"unexpected-response-shape","analyzedSha":"2404aceecc08b0b2d100fedc96f57745cd5904dc","analyzedAt":"2026-09-13T19:13:33.814Z","contentChangedAt":"2026-09-13T19:13:33.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}