From 0826d2cf8d4580871420865e04e472ba83e5bce7 Mon Sep 17 00:00:00 2001 From: slaff Date: Tue, 8 Dec 2020 22:17:35 +0100 Subject: [PATCH] Improve connection:close handling for HTTP clients. (#2175) --- Sming/Core/Network/Http/HttpClientConnection.cpp | 4 ++-- Sming/Core/Network/Http/HttpClientConnection.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sming/Core/Network/Http/HttpClientConnection.cpp b/Sming/Core/Network/Http/HttpClientConnection.cpp index 8ae3701ff8..cac3f32ce5 100644 --- a/Sming/Core/Network/Http/HttpClientConnection.cpp +++ b/Sming/Core/Network/Http/HttpClientConnection.cpp @@ -143,7 +143,8 @@ int HttpClientConnection::onMessageComplete(http_parser* parser) // if the server does not support keep-alive -> close the connection // see: https://tools.ietf.org/html/rfc2616#section-14.10 debug_d("HCC::onMessageComplete: Closing as requested by server"); - close(); + state = eHCS_WaitResponse; // put the other requests on hold... + setTimeOut(0); // schedule for closing... return hasError; } @@ -312,7 +313,6 @@ void HttpClientConnection::onClosed() debug_d("HCC::onClosed: Trying to reconnect and send pending requests"); cleanup(); - init(HTTP_RESPONSE); auto request = waitingQueue.peek(); if(request != nullptr) { bool useSsl = (request->uri.Scheme == URI_SCHEME_HTTP_SECURE); diff --git a/Sming/Core/Network/Http/HttpClientConnection.h b/Sming/Core/Network/Http/HttpClientConnection.h index 8b72f8cd7c..0cf6301080 100644 --- a/Sming/Core/Network/Http/HttpClientConnection.h +++ b/Sming/Core/Network/Http/HttpClientConnection.h @@ -86,6 +86,7 @@ class HttpClientConnection : public HttpConnection { if(err == ERR_OK) { state = eHCS_Ready; + init(HTTP_RESPONSE); } return HttpConnection::onConnected(err);