Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS 7.5: Force Keep Alive header in Response

Based on my research, IIS 7.5 doesn't include the Connection:Keep-Alive in its response for reasons described here. Unfortunately, I have a non conforming client connecting to my web service that won't reuse sockets unless it sees Connection:Keep-Alive in the response header. I've tried programmatically adding this header but IIS appears to purposely strip it out. Is there any other way that I can force this header to be sent back to my naughty client?

like image 778
Mitch A Avatar asked Nov 06 '13 18:11

Mitch A


People also ask

How to Set keep alive header?

The Keep-Alive header is a general-type header. This header is used to hint at how the connection may be used to set a timeout and a maximum amount of requests. It can also be used to allow a single TCP connection to remain open for multiple HTTP requests/responses (default HTTP connection closed after each request).

How to Set Connection keep alive?

To enable Keep-Alive, you need to explicitly request it via the HTTP header by accessing . htaccess or the main configuration file of your web server. If you turn on Keep-Alive, the HTTP response header will show Connection: keep-alive.

What is keep alive timeout?

The keep alive timeout on the Message Processor allows a single TCP connection to send and receive multiple HTTP requests/responses from/to the backend server, instead of opening a new connection for every request/response pair.

What does HTTP keep alive do?

HTTP keep-alive, a.k.a., HTTP persistent connection, is an instruction that allows a single TCP connection to remain open for multiple HTTP requests/responses. By default, HTTP connections close after each request.


1 Answers

I opened a support ticket with Microsoft on this and had my worst suspicions confirmed. IIS 7.5 deliberately prevents the connection:keep-alive header from being returned in the response. Per the HTTP 1.1 RFC, all connections should assume keep alive (a departure from HTTP 1.0). Therefore, the omission of this header is the default and correct (?) behavior. When keep-alives are not desirable, IIS will send the connection:close header.

What really surprised me is the great lengths to which IIS will go to to prevent this header from being sent. Something within the IIS pipeline strips out this header no matter how it is added. (C# code in my MVC application, IIS Manager-->HTTP Response Headers,IIS Manager-->URL Rewrite Module).

You would think MS would allow some sort of escape valve on this, given that there are so many non-conforming HTTP 1.1 clients in the wild that simply will not behave unless they see this header.

like image 125
Mitch A Avatar answered Nov 13 '22 09:11

Mitch A