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
Added global HTTP response headers configuration. Resolves #3788. #4596
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment about where this setting should live in the host.json -- I think @soninaren may have to change the hsts as well. It seems like these should live under extensions -> http
.
test/WebJobs.Script.Tests.Integration/TestScripts/CustomHeadersMiddleware/CSharp/host.json
Outdated
Show resolved
Hide resolved
|
||
public CustomHeadersMiddleware(IOptions<ScriptJobHostOptions> hostOptions) | ||
{ | ||
RequestDelegate contextNext = async context => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this pattern is in place here because of what was done in the HSTS middleware, but this middleware doesn't have the same requirements, so you should be able to simplify this and make it a bit more efficient.
Something as simple as this should just work:
public class CustomHeadersMiddleware : IJobHostHttpMiddleware
{
private readonly ScriptJobHostOptions _hostOptions;
public CustomHeadersMiddleware(IOptions<ScriptJobHostOptions> hostOptions)
{
_hostOptions = hostOptions.Value;
}
public async Task Invoke(HttpContext context, RequestDelegate next)
{
await next(context);
foreach (var header in _hostOptions.CustomHeaders)
{
context.Response.Headers[header.Key] = header.Value;
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do. More for my own curiosity than anything else, and to better understand this part of the codebase, what were the requirements for the HSTS middleware that necessitated the pattern Naren used?
src/WebJobs.Script.WebHost/Middleware/CustomHeadersMiddleware.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor nit comment (to avoid an additional file change), but this is good to go!
07654c4
to
54bcd9b
Compare
@kashimiz are you still waiting on anything to merge this? |
54bcd9b
to
baafa64
Compare
baafa64
to
6c5dd3b
Compare
Resolves #3788
Global HTTP headers are configured at the root host.json level, ex.:
I chose the name
customHeaders
for its familiarity to ASP.NET Core developers, being used for the same purpose in web.config.