Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • That middleware handles incoming requests to your web server. Is this for an outgoing http request from your server code to another server? If not, can you clarify exactly which header you're trying to modify. Commented Oct 13, 2018 at 13:27
  • @sellotape yes, I need to modify the Outgoing requests. Commented Oct 13, 2018 at 13:48
  • 1
    That's unrelated to the middleware you refer to then. Assuming you're using HttpWebRequest, that header is added just before sending, with no hooks you can use to alter it. You could try set .KeepAlive = false;, which should stop the header being added, then add your own header before sending, but... there is more going on behind the scenes with keep-alive connections than simply this header. It also begs the question of why the server you're calling needs it; all the HTTP specs refer to "Keep-Alive". Commented Oct 13, 2018 at 14:40
  • FYI .KeepAlive = false; + adding my own will result in combined header Connection: keep-alive, close Commented Oct 13, 2018 at 14:47
  • 1
    @realPro - yeah, it will add "close" if KeepAlive is false. See the source here - line 5047. There doesn't seem much you can do about it. I'd complain to the provider of the server you're calling instead. Commented Oct 13, 2018 at 15:08