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

Add Content-Type as default header that is set #186

Merged
merged 2 commits into from
Sep 1, 2022

Conversation

twsouthwick
Copy link
Member

This was a default value that it appears some internal teams had relied on and caused problems when they were migrating. This change expands an existing middleware to handle adding any default response headers

This was a default value that it appears some internal teams had relied on and caused problems when they were migrating. This change expands an existing middleware to handle adding any default response headers
Copy link
Member

@mjrousos mjrousos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One question about whether it makes sense to set these headers before or after subsequent middleware run, but either way likely works.

{
foreach (var (header, value) in _defaultHeaders)
{
if (!context.Response.Headers.ContainsKey(header))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only set headers that aren't already present, should we call _next first so that whatever endpoint handles the request has an opportunity to write headers and we'll only set the default ones if they're still unset after that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't really do that because after _next(context) the response will have started writing. The alternative would be to register a Response.OnStarting delegate that would handle it there. Let me think about the implications of either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I'm ok with keeping this model if it's simpler.

@twsouthwick twsouthwick merged commit dd9adb1 into main Sep 1, 2022
@twsouthwick twsouthwick deleted the tasou/set-default-response-headers branch September 1, 2022 01:14
CZEMacLeod pushed a commit to CZEMacLeod/systemweb-adapters that referenced this pull request Sep 5, 2022
This was a default value that it appears some internal teams had relied on and caused problems when they were migrating. This change expands an existing middleware to handle adding any default response headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants