{"record":{"id":"a39ddb12e8b58664","repo":"dotnet/yarp","slug":"headername-cannot-be-null-or-empty-a39ddb","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/ResponseHeaderRemoveTransform.cs","lineNumber":18,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nusing System;\nusing System.Threading.Tasks;\n\nnamespace Yarp.ReverseProxy.Transforms;\n\n/// <summary>\n/// Removes a response header.\n/// </summary>\npublic class ResponseHeaderRemoveTransform : ResponseTransform\n{\n    public ResponseHeaderRemoveTransform(string headerName, ResponseCondition condition)\n    {\n        if (string.IsNullOrEmpty(headerName))\n        {\n            throw new ArgumentException($\"'{nameof(headerName)}' cannot be null or empty.\", nameof(headerName));\n        }\n\n        HeaderName = headerName;\n        Condition = condition;\n    }\n\n    internal string HeaderName { get; }\n\n    internal ResponseCondition Condition { get; }\n\n    // Assumes the response status code has been set on the HttpContext already.\n    /// <inheritdoc/>\n    public override ValueTask ApplyAsync(ResponseTransformContext context)\n    {\n        ArgumentNullException.ThrowIfNull(context);\n\n        if (Condition == ResponseCondition.Always\n            || Success(context) == (Condition == ResponseCondition.Success))","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Transforms/ResponseHeaderRemoveTransform.cs#L1-L36","documentation":"ResponseHeaderRemoveTransform's constructor throws ArgumentException when headerName is null or empty. The transform removes a named response header, so a concrete name is required. The constructor also accepts a ResponseCondition (Always/Success/Failure) controlling when removal applies.","triggerScenarios":"Constructing `new ResponseHeaderRemoveTransform(headerName, condition)` with a null/empty headerName. Reached via config when a 'ResponseHeaderRemove' value is empty, or programmatically.","commonSituations":"Config `{ \"ResponseHeaderRemove\": \"\" }`; a programmatic transform with an uninitialised name variable; dynamic header list yielding an empty entry.","solutions":["Provide a real response header name, e.g. \"Server\".","Populate the config ResponseHeaderRemove value.","Filter empty strings from dynamically generated lists before constructing."],"exampleFix":"// before\n{ \"ResponseHeaderRemove\": \"\" }\n// after\n{ \"ResponseHeaderRemove\": \"Server\" }","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(headerName))\n    throw new InvalidOperationException(\"A response header name is required to remove.\");\nvar t = new ResponseHeaderRemoveTransform(headerName, condition);","typeGuard":"static bool IsValidHeaderName(string? name)\n    => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":null,"preventionTips":["Filter empty entries from dynamic header-name lists before constructing.","Validate config ResponseHeaderRemove values are non-empty.","Prefer context.AddResponseHeaderRemove from validated config."],"tags":["yarp","transforms","argument-validation","headers","response"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}