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

Closed
tdykstra opened this issue Jan 11, 2025 · 4 comments · Fixed by #34666
Closed

Min API: How to modify headers in responses #34471

tdykstra opened this issue Jan 11, 2025 · 4 comments · Fixed by #34666
Assignees
Labels
aspnet-core/svc doc-enhancement fundamentals/subsvc okr-health Content health internal initiative seQUESTered Identifies that an issue has been imported into Quest. 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


Associated WorkItem - 371158

@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
@wadepickett
Copy link
Contributor

wadepickett commented Jan 24, 2025

Notes: This topic is also on the high traffic list for topics that need to be updated as part of the freshness effort. Maske sure I update the date after addressing this issue and reviewing the topic as a whole. Also see open issue on this topic: #33588

@timdeschryver
Copy link
Contributor

Hello @wadepickett if you want I can add your example to the "Minimal Apis quick reference" page (this issue). I would suggest to also include it on the Create responses page as it is very similar.

However, instead of adding it behind the string examples, I was thinking to create a new sub-header.

About the review and refresh, I think there's no new features released in 9.0 that can be added to these pages.

@wadepickett
Copy link
Contributor

@timdeschryver, sounds great! A new sub section seems right for this. I was not putting this on my plate to think through any further until next sprint when I had time to take it on given other high priority work we are trying to wrap up, so I just made these initial notes after looking it over a few minutes in triage.

I think your suggestions are great. If you want to take on this one, it is really appreciated.

@dotnetrepoman dotnetrepoman bot added the mapQuest clean move label Feb 7, 2025
@wadepickett wadepickett moved this from 🔖 Ready to ✅ Done in dotnet/AspNetCore.Docs February 2025 sprint Feb 7, 2025
@dotnet-policy-service dotnet-policy-service bot removed the mapQuest clean move label Feb 7, 2025
@wadepickett wadepickett added reQUEST Triggers an issue to be imported into Quest mapQuest clean move labels Feb 7, 2025
@dotnet-policy-service dotnet-policy-service bot removed the mapQuest clean move label Feb 7, 2025
@sequestor sequestor bot added seQUESTered Identifies that an issue has been imported into Quest. and removed reQUEST Triggers an issue to be imported into Quest labels Feb 8, 2025
@dotnetrepoman dotnetrepoman bot added the mapQuest clean move label Mar 4, 2025
@dotnet-policy-service dotnet-policy-service bot removed the mapQuest clean move label Mar 4, 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 seQUESTered Identifies that an issue has been imported into Quest. Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants