public async Task Invoke_hasCustomHeaders_AddsResponseHeaders() { var headers = new CustomHttpHeadersOptions { { "X-Content-Type-Options", "nosniff" }, { "Feature-Policy", "camera 'none'; geolocation 'none'" } }; var headerOptions = new OptionsWrapper <CustomHttpHeadersOptions>(headers); bool nextInvoked = false; RequestDelegate next = (context) => { nextInvoked = true; context.Response.StatusCode = (int)HttpStatusCode.Accepted; return(Task.CompletedTask); }; var middleware = new CustomHttpHeadersMiddleware(headerOptions); var httpContext = new DefaultHttpContext(); await middleware.Invoke(httpContext, next); Assert.True(nextInvoked); Assert.Equal(httpContext.Response.Headers["X-Content-Type-Options"].ToString(), "nosniff"); Assert.Equal(httpContext.Response.Headers["Feature-Policy"].ToString(), "camera 'none'; geolocation 'none'"); }
public async Task Invoke_noCustomHeaders_DoesNotAddResponseHeader() { var headerOptions = new OptionsWrapper <CustomHttpHeadersOptions>(new CustomHttpHeadersOptions()); bool nextInvoked = false; RequestDelegate next = (context) => { nextInvoked = true; context.Response.StatusCode = (int)HttpStatusCode.Accepted; return(Task.CompletedTask); }; var middleware = new CustomHttpHeadersMiddleware(headerOptions); var httpContext = new DefaultHttpContext(); await middleware.Invoke(httpContext, next); Assert.True(nextInvoked); Assert.Equal(httpContext.Response.Headers.Count, 0); }