Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created June 19, 2012 12:12
Show Gist options
  • Save tugberkugurlu/2953810 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/2953810 to your computer and use it in GitHub Desktop.
public class WebApiApplication : System.Web.HttpApplication {
protected void Application_Start() {
//...
GlobalConfiguration.Configuration.MessageHandlers.Add(new RemoveServerHeaderMessageHandler());
}
}
public class RemoveServerHeaderMessageHandler : DelegatingHandler {
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) {
return base.SendAsync(request, cancellationToken).ContinueWith(task => {
var response = task.Result;
var httpContext = response.RequestMessage.Properties["MS_HttpContext"] as HttpContextWrapper;
if (httpContext != null)
httpContext.Response.Headers.Remove("Server");
return response;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment