{"record":{"id":"926b1bc467535eeb","repo":"dotnet/yarp","slug":"headername-cannot-be-null-or-empty-926b1b","errorCode":null,"errorMessage":"'headerName' cannot be null or empty.","messagePattern":"'headerName' cannot be null or empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ReverseProxy/Transforms/ResponseTransform.cs","lineNumber":38,"sourceCode":"    /// </summary>\n    public abstract ValueTask ApplyAsync(ResponseTransformContext context);\n\n    /// <summary>\n    /// Removes and returns the current header value by first checking the HttpResponse\n    /// and falling back to the value from HttpResponseMessage or HttpContent only if\n    /// <see cref=\"ResponseTransformContext.HeadersCopied\"/> is not set.\n    /// This ordering allows multiple transforms to mutate the same header.\n    /// </summary>\n    /// <param name=\"context\">The transform context.</param>\n    /// <param name=\"headerName\">The name of the header to take.</param>\n    /// <returns>The response header value, or StringValues.Empty if none.</returns>\n    public static StringValues TakeHeader(ResponseTransformContext context, string headerName)\n    {\n        ArgumentNullException.ThrowIfNull(context);\n\n        if (string.IsNullOrEmpty(headerName))\n        {\n            throw new ArgumentException($\"'{nameof(headerName)}' cannot be null or empty.\", nameof(headerName));\n        }\n\n        if (context.HttpContext.Response.Headers.TryGetValue(headerName, out var existingValues))\n        {\n            context.HttpContext.Response.Headers.Remove(headerName);\n        }\n        else if (context.ProxyResponse is { } proxyResponse && !context.HeadersCopied)\n        {\n            if (!RequestUtilities.TryGetValues(proxyResponse.Headers, headerName, out existingValues))\n            {\n                RequestUtilities.TryGetValues(proxyResponse.Content.Headers, headerName, out existingValues);\n            }\n        }\n\n        return existingValues;\n    }\n\n    /// <summary>","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Transforms/ResponseTransform.cs#L20-L56","documentation":"ResponseTransform.TakeHeader is a static helper that extracts and removes a response header value from the HttpContext.Response (or the proxy response if headers have not been copied yet). It throws ArgumentException when headerName is null or empty, because it cannot locate a header without a name. Custom response transforms calling this helper with an empty name hit it.","triggerScenarios":"A custom ResponseTransform implementation calling `ResponseTransform.TakeHeader(context, headerName)` where headerName is null or empty. This is a developer-API path for custom transform authors.","commonSituations":"A custom transform iterating over header names where one is empty; headerName sourced from a route value or config that resolved to empty; copy-pasted transform stub.","solutions":["Pass a concrete header name to TakeHeader.","Skip empty entries when iterating header-name collections.","Guard with a null/empty check before calling TakeHeader."],"exampleFix":"// before\nvar val = ResponseTransform.TakeHeader(context, headerName /* possibly empty */);\n// after\nif (!string.IsNullOrEmpty(headerName))\n{\n    var val = ResponseTransform.TakeHeader(context, headerName);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(headerName))\n{\n    // skip or log; do not call TakeHeader with an empty name\n    return;\n}\nvar value = ResponseTransform.TakeHeader(context, headerName);","typeGuard":"static bool IsValidHeaderName(string? name)\n    => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":null,"preventionTips":["In custom response transforms, guard TakeHeader with a null/empty check.","Filter empty strings from header-name collections before iterating.","Unit-test your custom transform with an empty header name to confirm graceful handling."],"tags":["yarp","transforms","argument-validation","headers","response","custom-transform"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}