From 4059dd644ccd7e2f3d661a786c7f4ca6449bfa40 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sun, 28 Oct 2018 02:08:01 +0100 Subject: [PATCH] Abort logic fixes --- src/HttpContext.h | 2 +- src/HttpResponse.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/HttpContext.h b/src/HttpContext.h index c9e4daf..c8a3c65 100644 --- a/src/HttpContext.h +++ b/src/HttpContext.h @@ -66,7 +66,7 @@ private: std::cout << "Close event!" << std::endl; - /* Signal broken HTTP request */ + /* Signal broken HTTP request only if we have a pending request */ if (httpResponseData->onAborted) { httpResponseData->onAborted(); } diff --git a/src/HttpResponse.h b/src/HttpResponse.h index 0a6b129..9c566b4 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -105,6 +105,13 @@ private: Super::timeout(HTTP_TIMEOUT_S); } + /* Remove onAborted function if we reach the end */ + if (httpResponseData->offset == totalSize) { + httpResponseData->onAborted = nullptr; + /* Also remove onWritable so that we do not emit when draining behind the scenes. */ + httpResponseData->onWritable = nullptr; + } + return success; } }