title: ASP.NET Core Modify HTTP Request Headers using Middleware
body: <p>All I need to do is to modify <code>[Connection]</code> HTTP Header from "Keep-alive" to lowercase "keep-alive".</p>
  
  <p>I wrote the class, </p>
  
  <pre><code>public class PreRequestModifications
  {
  
      private readonly RequestDelegate _next;
  
      public PreRequestModifications(RequestDelegate next)
      {
          _next = next;
      }
  
      public async Task Invoke(HttpContext context)
      {
          // Does not get called when making an HTTPWebRequest.   
          await _next.Invoke(context);              
      }
  }
  </code></pre>
  
  <p>and registered on startup, </p>
  
  <pre><code> public void Configure(IApplicationBuilder app, IHostingEnvironment env)
   {    
       app.UseMiddleware&lt;PreRequestModifications&gt;();
   }
  </code></pre>
  
  <p>but the <code>Invoke</code> method does not get called when I execute <code>await httpWebRequest.GetResponseAsync();</code></p>