{"record":{"id":"ab8e82c4078f7309","repo":"dotnet/yarp","slug":"headername-cannot-be-null-or-empty-ab8e82","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/ResponseHeaderValueTransform.cs","lineNumber":19,"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;\nusing Microsoft.Extensions.Primitives;\n\nnamespace Yarp.ReverseProxy.Transforms;\n\n/// <summary>\n/// Sets or appends simple response header values.\n/// </summary>\npublic class ResponseHeaderValueTransform : ResponseTransform\n{\n    public ResponseHeaderValueTransform(string headerName, string value, bool append, 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        ArgumentNullException.ThrowIfNull(value);\n        Value = value;\n        Append = append;\n        Condition = condition;\n    }\n\n    internal ResponseCondition Condition { get; }\n\n    internal bool Append { get; }\n\n    internal string HeaderName { get; }\n\n    internal string Value { get; }\n\n    // Assumes the response status code has been set on the HttpContext already.","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Transforms/ResponseHeaderValueTransform.cs#L1-L37","documentation":"ResponseHeaderValueTransform's constructor validates headerName (non-null/non-empty) and value (non-null via ArgumentNullException). The transform sets or appends a simple response header value, so both the name and the value must be concrete. A ResponseCondition controls when it applies.","triggerScenarios":"Constructing `new ResponseHeaderValueTransform(headerName, value, append, condition)` where headerName is null or empty. Via config this is the 'ResponseHeader' key value; an empty string triggers it.","commonSituations":"Config `{ \"ResponseHeader\": \"\", \"Set\": \"x\" }`; a programmatic transform registration with an empty header name; refactoring that cleared the variable.","solutions":["Pass a non-empty header name such as \"X-Custom-Header\".","Ensure the config ResponseHeader value is populated.","Validate headerName at the call site before constructing."],"exampleFix":"// before\nnew ResponseHeaderValueTransform(\"\", \"v\", false, ResponseCondition.Always);\n// after\nnew ResponseHeaderValueTransform(\"X-Custom-Header\", \"v\", false, ResponseCondition.Always);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(headerName))\n    throw new InvalidOperationException(\"Response header name is required.\");\nif (value is null)\n    throw new InvalidOperationException(\"Response header value is required.\");\nvar t = new ResponseHeaderValueTransform(headerName, value, append, condition);","typeGuard":"static bool IsValidHeaderAndValue(string? name, string? value)\n    => !string.IsNullOrWhiteSpace(name) && value is not null;","tryCatchPattern":null,"preventionTips":["Validate both headerName and value before constructing.","Ensure config ResponseHeader/Set values are populated.","Use context.AddResponseHeader 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-14T05:17:29.042Z"}