{"record":{"id":"86af78384daf8379","repo":"xai-org/grok-build","slug":"response-missing-content-length","errorCode":null,"errorMessage":"response missing Content-Length","messagePattern":"response missing Content-Length","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-update/src/auto_update.rs","lineNumber":1105,"sourceCode":"\n/// Try a parallel byte-range download to `dest`. Returns Err if the server\n/// doesn't advertise a Content-Length, the file is too small to be worth\n/// splitting, the range request is rejected, or any chunk transfer fails.\n/// The caller is expected to fall back to a single-connection download on Err.\nasync fn try_parallel_download(\n    url: &str,\n    dest: &std::path::Path,\n    with_progress: bool,\n) -> Result<()> {\n    let client = download_client()?;\n\n    let head = client.head(url).send().await?;\n    if !head.status().is_success() {\n        anyhow::bail!(\"HEAD failed: HTTP {}\", head.status());\n    }\n    let size = head\n        .content_length()\n        .ok_or_else(|| anyhow::anyhow!(\"response missing Content-Length\"))?;\n    if size < PARALLEL_DOWNLOAD_MIN_BYTES {\n        anyhow::bail!(\"file too small for parallel download ({} bytes)\", size);\n    }\n\n    let n_chunks = parallel_chunk_count(size);\n    if n_chunks < 2 {\n        anyhow::bail!(\n            \"file size yields {} chunk(s); not worth parallelizing\",\n            n_chunks\n        );\n    }\n    let chunk_size = size.div_ceil(n_chunks);\n\n    let pb = if with_progress {\n        let pb = ProgressBar::new(size);\n        pb.set_style(\n            ProgressStyle::default_bar()\n                .template(\"  {bar:30.cyan/dim} {bytes}/{total_bytes} ({eta})\")","sourceCodeStart":1087,"sourceCodeEnd":1123,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-update/src/auto_update.rs#L1087-L1123","documentation":"try_parallel_download first issues a HEAD request to learn the file size and validate that parallel range downloads are worthwhile. If the successful HEAD response carries no Content-Length header, the size is unknown and this error is thrown because chunked range downloads cannot be planned without it.","triggerScenarios":"Calling download_with_progress / download_silent against a server whose HEAD response for the artifact URL omits Content-Length — e.g. chunked transfer encoding, compression middleware, or a CDN rewriting HEAD responses.","commonSituations":"Downloading through a reverse proxy or CDN that strips/omits Content-Length on HEAD; servers that respond 200 with chunked encoding instead of a length; enterprise proxies that transform responses; misconfigured artifact mirror.","solutions":["Fall back to the non-parallel single-stream download path when Content-Length is missing","Verify with `curl -I <url>` whether the server returns Content-Length on HEAD","Bypass or reconfigure the proxy/CDN that is stripping the header","Point the download at the canonical artifact URL/mirror that serves proper HEAD metadata"],"exampleFix":"// before\nlet size = head.content_length()\n    .ok_or_else(|| anyhow::anyhow!(\"response missing Content-Length\"))?;\n// after\nmatch head.content_length() {\n    Some(size) if size >= PARALLEL_DOWNLOAD_MIN_BYTES => download_parallel(url, size).await,\n    _ => download_single_stream(url).await, // graceful fallback\n}","handlingStrategy":"fallback","validationCode":"let head = client.head(url).send().await?;\nlet has_len = head.content_length().is_some();\nif !has_len { eprintln!(\"server omitted Content-Length; use single-stream download\"); }","typeGuard":"fn supports_parallel_download(head: &reqwest::Response) -> bool {\n    head.status().is_success() && head.content_length().map_or(false, |n| n >= PARALLEL_DOWNLOAD_MIN_BYTES)\n}","tryCatchPattern":"match download_with_progress(url, &dest).await {\n    Err(e) if e.to_string().contains(\"response missing Content-Length\") => {\n        download_single_stream(url, &dest).await?; // fallback\n    }\n    other => other,\n}","preventionTips":["Test artifact URLs with `curl -I` to confirm Content-Length on HEAD","Avoid proxies/CDNs that strip HEAD metadata","Always implement a single-stream fallback for downloads","Prefer mirrors known to serve proper HEAD responses"],"tags":["network","http","download","content-length"],"backgroundTag":"missing-content-length","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}