elsa-workflows/elsa-core · warning · HttpBadRequestException
Failed to parse If-Match header value
Error message
Failed to parse If-Match header value
What it means
WriteFileHttpResponse validates conditional requests via the If-Match header for optimistic concurrency. GetIfMatchHeaderValue parses the header into an EntityTagHeaderValue; malformed ETags (missing quotes, stray characters) cause the parse to fail and the activity throws HttpBadRequestException with message 'Failed to parse If-Match header value', rejecting the request as a client error.
Solutions
- Send the ETag exactly as received, including quotes and any W/ weak validator prefix, e.g. 'If-Match: "33a64df551425fcc55e4d42a148795d9f25f89d4"'.
- Omit the If-Match header if conditional validation is not required.
- Handle the HttpBadRequestException to return a 400 with guidance on ETag format to API consumers.
Example fix
// before (client request header) If-Match: 33a64df551425fcc55e4d42a148795d9f25f89d4 // after If-Match: "33a64df551425fcc55e4d42a148795d9f25f89d4"
Defensive patterns
Strategy: validation
Validate before calling
// Client side: ensure the ETag is quoted before sending If-Match
string FormatIfMatch(string etag) => etag.StartsWith('"') ? etag : $"\"{etag.Trim('W', '/')}\""; Try / catch
try
{
await workflowRunner.RunAsync(workflow, request);
}
catch (HttpBadRequestException ex) when (ex.Message.Contains("If-Match"))
{
httpContext.Response.StatusCode = 400;
await httpContext.Response.WriteAsJsonAsync(new { error = "If-Match must be a quoted ETag" });
} Prevention
- Always store and re-send ETags verbatim, including quotes and W/ prefix.
- Avoid constructing If-Match headers by string concatenation without quoting.
- Only send If-Match when optimistic concurrency is actually needed.
When it happens
Trigger: A client supplies an If-Match header that is not a valid ETag — e.g., 'If-Match: abc123' (unquoted), 'If-Match: W/weak-without-quotes', or containing commas/invalid characters — while WriteFileHttpResponse evaluates preconditions.
Common situations: Clients storing the ETag and re-sending it without the surrounding quotes, manually built curl requests omitting quotes around the tag, or intermediary systems corrupting the header value.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse Range header value
- The workflow definition has been written since the ETag in…
- RequestBodyTooLargeException
- The identity provider metadata could not be resolved.
- The identity provider token exchange failed.
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/ba307ab76a59c675.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Http/Activities/WriteFileHttpResponse.cs:294
return headers.TryGetValue(HeaderNames.Range, out var header) ? RangeHeaderValue.Parse(header.ToString()) : null;
}
catch (Exception e)
{
throw new HttpBadRequestException("Failed to parse Range header value", e);
}
}
private static EntityTagHeaderValue? GetIfMatchHeaderValue(IHeaderDictionary headers)
{
try
{
return headers.TryGetValue(HeaderNames.IfMatch, out var header) ? new EntityTagHeaderValue(header.ToString()) : null;
}
catch (Exception e)
{
throw new HttpBadRequestException("Failed to parse If-Match header value", e);
}
}
}
View on GitHub (pinned to fe9217bdfa)