From 36857c1f3d62b90de910f17586f8b0eb51b30060 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Tue, 3 Dec 2019 16:21:04 -0500
Subject: [PATCH] http/request: add aborted flag and actual status code

---
 include/opendht/http.h | 3 ++-
 src/http.cpp           | 6 ++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/opendht/http.h b/include/opendht/http.h
index 91c233bd..d43e78cb 100644
--- a/include/opendht/http.h
+++ b/include/opendht/http.h
@@ -192,9 +192,10 @@ private:
 
 struct Response
 {
-    unsigned int status_code;
+    unsigned int status_code {0};
     std::map<std::string, std::string> headers;
     std::string body;
+    bool aborted {false};
 };
 
 class OPENDHT_PUBLIC Request : public std::enable_shared_from_this<Request>
diff --git a/src/http.cpp b/src/http.cpp
index c6b90341..0017b0d0 100644
--- a/src/http.cpp
+++ b/src/http.cpp
@@ -875,12 +875,14 @@ Request::terminate(const asio::error_code& ec)
 
     // set response outcome, ignore end of file and abort
     if (!ec or ec == asio::error::eof)
-        response_.status_code = 200;
+        response_.status_code = parser_->status_code;
     else
         response_.status_code = 0;
 
+    response_.aborted = ec == asio::error::operation_aborted;
+
     if (logger_)
-        logger_->d("[http:request:%i] done", id_);
+        logger_->d("[http:request:%i] done with status code %u", id_, parser_->status_code);
     if (connection_type_ != restinio::http_connection_header_t::keep_alive)
         if (auto c = conn_)
             c->close();
-- 
GitLab