{"record":{"id":"6c7153236f34fd55","repo":"iawia002/lux","slug":"content-length-is-not-present","errorCode":null,"errorMessage":"Content-Length is not present","messagePattern":"Content-Length is not present","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"request/request.go","lineNumber":200,"sourceCode":"\t\t\"Referer\": refer,\n\t}\n\tres, err := Request(http.MethodGet, url, nil, headers)\n\tif err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\tdefer res.Body.Close() // nolint\n\treturn res.Header, nil\n}\n\n// Size get size of the url\nfunc Size(url, refer string) (int64, error) {\n\th, err := Headers(url, refer)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\ts := h.Get(\"Content-Length\")\n\tif s == \"\" {\n\t\treturn 0, errors.New(\"Content-Length is not present\")\n\t}\n\tsize, err := strconv.ParseInt(s, 10, 64)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn size, nil\n}\n\n// ContentType get Content-Type of the url\nfunc ContentType(url, refer string) (string, error) {\n\th, err := Headers(url, refer)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\ts := h.Get(\"Content-Type\")\n\t// handle Content-Type like this: \"text/html; charset=utf-8\"\n\treturn strings.Split(s, \";\")[0], nil\n}","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/iawia002/lux/blob/dd00f6d258d80b6684a0b9402d7124e5c18ef42f/request/request.go#L182-L218","documentation":"request.Size fetches the response headers (via Headers) and reads the Content-Length header to determine file size. When the header is absent it returns this error. Servers replying with chunked transfer-encoding, or redirects ending at a page without a length, omit Content-Length even though the request succeeded.","triggerScenarios":"Any extractor calling request.Size against a media URL whose server responds with Transfer-Encoding: chunked, a 30x redirect chain ending on a page without Content-Length, or a CDN that omits the header for signed/pre-flight requests.","commonSituations":"HLS/DASH-style CDNs, dynamic endpoints, and some object stores behind proxies. Downloaders that need a size for progress reporting hit this on otherwise-downloadable streams.","solutions":["Fall back to a ranged GET (Range: bytes=0-0) and parse the total from the Content-Range header (bytes 0-0/TOTAL)","Or treat unknown size as -1/0 and stream-download with an indeterminate progress bar","Check with curl -sI whether the URL consistently lacks Content-Length; if it is a redirect, resolve the final URL first and size that","Patch request.Size in request/request.go to do the Content-Range fallback automatically"],"exampleFix":"// before\ns := h.Get(\"Content-Length\")\nif s == \"\" {\n    return 0, errors.New(\"Content-Length is not present\")\n}\n\n// after (ranged-GET fallback to Content-Range)\ns := h.Get(\"Content-Length\")\nif s == \"\" {\n    req, _ := http.NewRequest(http.MethodGet, url, nil)\n    req.Header.Set(\"Range\", \"bytes=0-0\")\n    res, err := client.Do(req)\n    if err == nil {\n        defer res.Body.Close() // nolint\n        if cr := res.Header.Get(\"Content-Range\"); cr != \"\" {\n            if total := strings.Split(cr, \"/\"); len(total) == 2 {\n                return strconv.ParseInt(total[1], 10, 64)\n            }\n        }\n    }\n    return 0, errors.New(\"Content-Length is not present\")\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"size, err := request.Size(mediaURL, referer)\nif err != nil && strings.Contains(err.Error(), \"Content-Length is not present\") {\n    // ranged GET fallback: total is in Content-Range 'bytes 0-0/TOTAL'\n    req, _ := http.NewRequest(http.MethodGet, mediaURL, nil)\n    req.Header.Set(\"Range\", \"bytes=0-0\")\n    if res, rerr := http.DefaultClient.Do(req); rerr == nil {\n        cr := res.Header.Get(\"Content-Range\")\n        res.Body.Close() // nolint\n        if parts := strings.Split(cr, \"/\"); len(parts) == 2 {\n            size, err = strconv.ParseInt(parts[1], 10, 64)\n        }\n    }\n    if err != nil {\n        size = -1 // proceed with unknown size\n    }\n}","preventionTips":["Never assume Content-Length exists; always code the Content-Range fallback","Resolve redirect chains to the final media URL before sizing","Design downloaders to proceed with unknown size instead of aborting"],"tags":["http","content-length","headers","size","chunked-encoding"],"backgroundTag":null,"analyzedSha":"dd00f6d258d80b6684a0b9402d7124e5c18ef42f","analyzedAt":"2026-08-15T16:57:31.080Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}