{"record":{"id":"c7df1bf1b705b280","repo":"elsa-workflows/elsa-core","slug":"failed-to-parse-range-header-value","errorCode":null,"errorMessage":"Failed to parse Range header value","messagePattern":"Failed to parse Range header value","errorType":"http","errorClass":"HttpBadRequestException","httpStatus":400,"severity":"warning","filePath":"src/modules/Elsa.Http/Activities/WriteFileHttpResponse.cs","lineNumber":281,"sourceCode":"        return manager.GetDownloadablesAsync(content, options, context.CancellationToken);\n    }\n\n    private string GetContentType(ActivityExecutionContext context, string filename)\n    {\n        var provider = context.GetRequiredService<IContentTypeProvider>();\n        return provider.TryGetContentType(filename, out var contentType) ? contentType : System.Net.Mime.MediaTypeNames.Application.Octet;\n    }\n    \n    private static RangeHeaderValue? GetRangeHeaderHeaderValue(IHeaderDictionary headers)\n    {\n        try\n        {\n            return headers.TryGetValue(HeaderNames.Range, out var header) ? RangeHeaderValue.Parse(header.ToString()) : null;\n            \n        }\n        catch (Exception e)\n        {\n            throw new HttpBadRequestException(\"Failed to parse Range header value\", e);\n        }\n    }\n    \n    private static EntityTagHeaderValue? GetIfMatchHeaderValue(IHeaderDictionary headers)\n    {\n        try\n        {\n            return headers.TryGetValue(HeaderNames.IfMatch, out var header) ? new EntityTagHeaderValue(header.ToString()) : null;\n            \n        }\n        catch (Exception e)\n        {\n            throw new HttpBadRequestException(\"Failed to parse If-Match header value\", e);\n        }\n    }\n}\n\n","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Http/Activities/WriteFileHttpResponse.cs#L263-L299","documentation":"When serving a file response, WriteFileHttpResponse supports HTTP Range requests for partial content. GetRangeHeaderHeaderValue parses the incoming Range header with RangeHeaderValue.Parse; if parsing fails, it wraps the parse error in an HttpBadRequestException with message 'Failed to parse Range header value'. A syntactically invalid Range header from the client is treated as a bad request.","triggerScenarios":"A client sends a Range header that is not a valid byte-range spec — e.g., 'Range: bytes=abc', 'Range: 0-10' (missing 'bytes=' unit is actually valid per some parsers but 'bytes=' with garbage indexes or multiple malformed ranges) — while the workflow executes WriteFileHttpResponse and reads the header.","commonSituations":"Custom download clients or scripts constructing Range headers manually with wrong syntax, proxies/CDNs mangling the header, or tests issuing hand-written ranges like 'bytes=-' or 'items=0-5'.","solutions":["Fix the client to send a spec-compliant header, e.g. 'Range: bytes=0-1023'.","Remove the Range header if partial content is not needed; the activity will return the full file (200) instead of 206.","Catch HttpBadRequestException around the workflow invocation / handle the fault to return a clear 400 to the calling client."],"exampleFix":"// before (client request header)\nRange: bytes=abc-xyz\n// after\nRange: bytes=0-1023","handlingStrategy":"validation","validationCode":"// Client side: validate the Range header before sending\nbool IsValidRange(string? range) =>\n    range is null || System.Text.RegularExpressions.Regex.IsMatch(range, \"^bytes=(\\\\d*-\\\\d*)(,\\\\s*\\\\d*-\\\\d*)*$\");\n// e.g. IsValidRange(\"bytes=0-1023\")","typeGuard":null,"tryCatchPattern":"try\n{\n    await workflowRunner.RunAsync(workflow, request);\n}\ncatch (HttpBadRequestException ex) when (ex.Message.Contains(\"Range header\"))\n{\n    httpContext.Response.StatusCode = 400;\n    await httpContext.Response.WriteAsJsonAsync(new { error = \"Invalid Range header; use 'bytes=start-end'\" });\n}","preventionTips":["Use spec-compliant 'bytes=start-end' syntax in download clients.","Test proxy/CDN configurations for header rewriting.","Omit the Range header when full-content downloads suffice."],"tags":["http","range-request","bad-request","headers"],"backgroundTag":"invalid-argument-format","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}