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; } }