wsd: http: support http Connection: close header
According to the RFC, HTTP/1.1 assumes persistent connection unless the client or server sends 'Connection: close' header. See https://tools.ietf.org/html/rfc7230#section-6.3 Now we fully support disconnecting when we get this header, which is important for when reusing the same http::Session (we need to reconnect in such a case). Change-Id: Ib278eff21be32c1414478296e90e2e807ab24132 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
parent
4b43b3cd6e
commit
d9fa64b4a0
1 changed files with 16 additions and 2 deletions
|
@ -1074,6 +1074,12 @@ private:
|
|||
LOG_TRC("onFinished calling client");
|
||||
_onFinished(std::static_pointer_cast<Session>(shared_from_this()));
|
||||
}
|
||||
|
||||
if (_response->get("Connection", "") == "close")
|
||||
{
|
||||
LOG_TRC("Our peer has sent the 'Connection: close' token. Disconnecting.");
|
||||
onDisconnect();
|
||||
}
|
||||
};
|
||||
|
||||
_response.reset(new Response(onFinished));
|
||||
|
@ -1147,12 +1153,22 @@ private:
|
|||
void onDisconnect() override
|
||||
{
|
||||
LOG_TRC("onDisconnect");
|
||||
|
||||
// Make sure the socket is disconnected and released.
|
||||
if (_socket)
|
||||
{
|
||||
_socket->shutdown(); // Flag for shutdown for housekeeping in SocketPoll.
|
||||
_socket->closeConnection(); // Immediately disconnect.
|
||||
_socket.reset();
|
||||
}
|
||||
|
||||
_connected = false;
|
||||
_response->complete();
|
||||
}
|
||||
|
||||
bool connect()
|
||||
{
|
||||
_socket.reset(); // Reset to make sure we are disconnected.
|
||||
_socket = net::connect(_host, _port, isSecure(), shared_from_this());
|
||||
return _socket != nullptr;
|
||||
}
|
||||
|
@ -1176,8 +1192,6 @@ private:
|
|||
// Disconnect and trigger the right events and handlers.
|
||||
// Note that this is the right way to end a request in HTTP, it's also
|
||||
// no good maintaining a poor connection (if that's the issue).
|
||||
_socket->shutdown(); // Flag for shutdown for housekeeping in SocketPoll.
|
||||
_socket->closeConnection(); // Immediately disconnect.
|
||||
onDisconnect(); // Trigger manually (why wait for poll to do it?).
|
||||
assert(_connected == false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue