Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Min API: How to modify headers in responses #34471

Open
tdykstra opened this issue Jan 11, 2025 · 1 comment
Open

Min API: How to modify headers in responses #34471

tdykstra opened this issue Jan 11, 2025 · 1 comment
Assignees
Labels
aspnet-core/svc doc-enhancement fundamentals/subsvc okr-health Content health internal initiative Source - Docs.ms Docs Customer feedback via GitHub Issue

Comments

@tdykstra
Copy link
Contributor

tdykstra commented Jan 11, 2025

Description

UUF verbatim:

Missing how to modify headers in responses.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-9.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/minimal-apis.md

Document ID

b09824ab-b051-75a1-13b7-b0e281cc46e0

Article author

@Rick-Anderson

Metadata

  • ID: b09824ab-b051-75a1-13b7-b0e281cc46e0
  • Service: aspnet-core
  • Sub-service: fundamentals

Related Issues

@tdykstra tdykstra added doc-enhancement Source - Docs.ms Docs Customer feedback via GitHub Issue labels Jan 11, 2025
@wadepickett wadepickett self-assigned this Jan 13, 2025
@wadepickett wadepickett changed the title Missing how to modify headers in responses Min API: How to modify headers in responses Jan 13, 2025
@wadepickett
Copy link
Contributor

wadepickett commented Jan 13, 2025

Notes: I should consider what we already have at:
https://learn.microsoft.com/en-us/aspnet/core/migration/http-modules#httpcontextresponse

See HttpContext.Response.Headers in that section and example we use for both single and multiple values:

    // Set header with single value
    httpContext.Response.Headers["ResponseHeaderName"] = "headerValue";

    // Set header with multiple values
    string[] responseHeaderValues = new string[] { "headerValue1", "headerValue1" };
    httpContext.Response.Headers["ResponseHeaderName"] = responseHeaderValues;

In this Min API doc under the Example Return values section, after the string return values example I might consider adding something like this:

Modifying Headers
You can modify headers in the response using the HttpResponse object. For example:

app.MapGet("/", (HttpContext context) => {
    context.Response.Headers["X-Custom-Header"] = "CustomValue";
    return "Hello World";
});

@wadepickett wadepickett added the okr-health Content health internal initiative label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aspnet-core/svc doc-enhancement fundamentals/subsvc okr-health Content health internal initiative Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

2 participants