Header "connection: close" disconnects the client before Response Stream is started
Describe the bug
In our project we use Drogon for HTTP response streaming.
However, when client includes connection header that is not keep-alive, response stream is immediaitely closed.
Source code: https://github.com/drogonframework/drogon/blob/cbf63f8fc4d849bbb82eeb1c83fcf8ff953f19f3/lib/src/HttpServer.cc#L981-L990
It is common practice to use connection: close to indicate that connection should be closed after processing is finished*, meaning - after HTTP response stream is done.
In our setup, we needed to patch drogon like this: https://github.com/openvinotoolkit/model_server/pull/3113/commits/8ca2918c04ae9fab77ad157dcd23673971d84420
To Reproduce Steps to reproduce the behavior:
- Start drogon with streaming response endpoint defined
- Request with any client including header
connection: close - Request is immediately rejected
Expected behavior Connection is closed after response streaming is finished.
Desktop (please complete the following information):
- OS: ubuntu, redhat, windows
- Client: any
More context
We are using Continue VSCode plugin as a client for code completions: https://github.com/continuedev/continue
We use drogon to serve http streaming (code completions), however, this plugin (client) sends connection: close header.
Thanks for using our framework!
This feature is introduced not long ago, we should ask for PR(#1886) author's opinion or explaination on this choice.
@tripleslash Could you check it out? Thanks a lot.
Sorry for the late reply @hwc0919
When a client sends a Connection: close header in an HTTP request to a Server-Sent Events (SSE) endpoint, it indicates that the client intends for the server to close the connection after completing the response. This behavior aligns with the HTTP/1.1 specification, which states that the "close" connection option signals that the connection will be closed after the current request/response is complete.
But here is the catch; SSE is designed to keep the connection open indefinitely, allowing the server to push events to the client as they occur. The server maintains an open connection, therefore, including Connection: close in the request contradicts the typical usage of SSE. If the server closes the connection upon receiving this header, it is imho conforming to the HTTP specification, even though it disrupts the SSE communication.
Tl;Dr: I think your client is not behaving properly. The question is, do you want drogons async streaming support to be forgiving vs. non-compliant clients?