Closed gyorokpeter closed 3 years ago
Hello @gyorokpeter, thanks for using EmbedIO!
Your requirement being a blatant violation of the HTTP protocol, I strongly doubt you'll find any web server library supporting it out-of-the.-box, including EmbedIO. I don't think a "forced keep-alive" feature would make much sense, either.
That said, I understand that sometimes one has to work with what one is given. If you're willing to use a private fork of EmbedIO, here's how to force keep-alive with the least possibile modifications.
Just insert the following line of code below this line in src/EmbedIO/Net/Internal/HttpListenerRequest.cs
(at the end of the FinishInitialization
method):
Headers.Set("Connection", "keep-alive");
As long as you use HttpListenerMode.EmbedIO
, this will make EmbedIO treat all incoming requests as if they contained a Connection
header with a value of keep-alive
and act accordingly.
DISCLAIMERS
EmbedIO
. Intellectual property matters aside, someone could install your fork by mistake and then face some weird, hard-to-figure-out bug in production.In that case I will keep my bespoke solution that implements HTTP over a standard TcpListener. The reason I wanted to use EmbedIO in the first place is because I wanted to integrate my code as a plugin to another app that already uses EmbedIO. So using a custom fork would not work.
[...] my bespoke solution that implements HTTP over a standard TcpListener.
Is that a private project, or may I take a look at it? We have to find a replacement for HttpListener before its status goes from the current "shamefully obsolete" to "covered in cobwebs" and any input is welcome.
I would like to implement a web server that doesn't close connections, it should be up to the client to close them, even if the client doesn't explicitly specify "Connection: keep-alive" in the headers. This is because a client may send many requests and handling them in separate connections would be too much overhead. The clients are pre-existing applications which are known to support sending multiple requests through the same connection.