http: enclose libevent-dependent code in a namespace
What changed, and why it matters
This commit only moves existing HTTP server code into a new namespace called http_libevent. It does not change any behavior, fix any bug, or alter how the software handles network input. It is a pure code-organization change to make future replacements easier to review.
No security action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff wraps existing libevent-dependent HTTP symbols (InitHTTPServer, StartHTTPServer, StopHTTPServer, InterruptHTTPServer, UpdateHTTPServerLogging, EventBase, HTTPRequest, GetQueryParameterFromUri) in a new namespace http_libevent and adds corresponding using-declarations at call sites. There are no logic, parsing, memory-management, or API changes. The commit message explicitly calls it a no-op preparatory refactor.
Changed components
src/httprpc.cppsrc/httpserver.cppsrc/httpserver.hsrc/init.cppsrc/rest.cppsrc/rpc/node.cppsrc/test/fuzz/http_request.cppsrc/test/httpserver_tests.cppInspect captured patch +25 / −5
diff --git a/src/httprpc.cpp b/src/httprpc.cpp
index 9a6b8eb0..2fc7f093 100644
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -26,6 +26,8 @@
#include <string>
#include <vector>
+using http_libevent::EventBase;
+using http_libevent::HTTPRequest;
using util::SplitString;
using util::TrimStringView;
diff --git a/src/httpserver.cpp b/src/httpserver.cpp
index 2e42eb0b..367e29ca 100644
--- a/src/httpserver.cpp
+++ b/src/httpserver.cpp
@@ -46,6 +46,7 @@
#include <support/events.h>
using common::InvalidPortErrMsg;
+using http_libevent::HTTPRequest;
/** Maximum size of http request (request line + headers) */
static const size_t MAX_HEADERS_SIZE = 8192;
@@ -381,6 +382,7 @@ static void libevent_log_cb(int severity, const char *msg)
}
}
+namespace http_libevent {
bool InitHTTPServer(const util::SignalInterrupt& interrupt)
{
if (!InitHTTPAllowList())
@@ -497,6 +499,7 @@ struct event_base* EventBase()
{
return eventBase;
}
+} // namespace http_libevent
static void httpevent_callback_fn(evutil_socket_t, short, void* data)
{
@@ -524,6 +527,8 @@ void HTTPEvent::trigger(struct timeval* tv)
else
evtimer_add(ev, tv); // trigger after timeval passed
}
+
+namespace http_libevent {
HTTPRequest::HTTPRequest(struct evhttp_request* _req, const util::SignalInterrupt& interrupt, bool _replySent)
: req(_req), m_interrupt(interrupt), replySent(_replySent)
{
@@ -686,6 +691,7 @@ std::optional<std::string> GetQueryParameterFromUri(const char* uri, const std::
return result;
}
+} // namespace http_libevent
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
{
diff --git a/src/httpserver.h b/src/httpserver.h
index 76381a38..5d6ea3c8 100644
--- a/src/httpserver.h
+++ b/src/httpserver.h
@@ -30,6 +30,8 @@ static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;
struct evhttp_request;
struct event_base;
class CService;
+
+namespace http_libevent {
class HTTPRequest;
/** Initialize HTTP server.
@@ -48,9 +50,10 @@ void StopHTTPServer();
/** Change logging level for libevent. */
void UpdateHTTPServerLogging(bool enable);
+} // namespace http_libevent
/** Handler for requests to a certain HTTP path */
-typedef std::function<void(HTTPRequest* req, const std::string &)> HTTPRequestHandler;
+typedef std::function<void(http_libevent::HTTPRequest* req, const std::string &)> HTTPRequestHandler;
/** Register handler for prefix.
* If multiple handlers match a prefix, the first-registered one will
* be invoked.
@@ -59,6 +62,7 @@ void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPR
/** Unregister handler for prefix */
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch);
+namespace http_libevent {
/** Return evhttp event base. This can be used by submodules to
* queue timers or custom events.
*/
@@ -158,6 +162,7 @@ public:
* @param[in] key represents the query parameter of which the value is returned
*/
std::optional<std::string> GetQueryParameterFromUri(const char* uri, const std::string& key);
+} // namespace http_libevent
/** Event class. This can be used either as a cross-thread trigger or as a timer.
*/
diff --git a/src/init.cpp b/src/init.cpp
index d2e29020..320940e4 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -145,6 +145,10 @@
using common::InvalidPortErrMsg;
using common::ResolveErrMsg;
+using http_libevent::InitHTTPServer;
+using http_libevent::InterruptHTTPServer;
+using http_libevent::StartHTTPServer;
+using http_libevent::StopHTTPServer;
using node::ApplyArgsManOptions;
using node::BlockManager;
using node::CalculateCacheSizes;
diff --git a/src/rest.cpp b/src/rest.cpp
index d2c5a9b4..5321cbee 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -37,6 +37,7 @@
#include <univalue.h>
+using http_libevent::HTTPRequest;
using node::GetTransaction;
using node::NodeContext;
using util::SplitString;
diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp
index 74d950ca..a43bf04d 100644
--- a/src/rpc/node.cpp
+++ b/src/rpc/node.cpp
@@ -264,7 +264,7 @@ static RPCMethod logging()
// Update libevent logging if BCLog::LIBEVENT has changed.
if (changed_log_categories & BCLog::LIBEVENT) {
- UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT));
+ http_libevent::UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT));
}
UniValue result(UniValue::VOBJ);
diff --git a/src/test/fuzz/http_request.cpp b/src/test/fuzz/http_request.cpp
index 9241060b..f64fb972 100644
--- a/src/test/fuzz/http_request.cpp
+++ b/src/test/fuzz/http_request.cpp
@@ -22,11 +22,12 @@
extern "C" int evhttp_parse_firstline_(struct evhttp_request*, struct evbuffer*);
extern "C" int evhttp_parse_headers_(struct evhttp_request*, struct evbuffer*);
-
-std::string RequestMethodString(HTTPRequest::RequestMethod m);
-
FUZZ_TARGET(http_request)
{
+ using http_libevent::HTTPRequest;
+
+ std::string RequestMethodString(HTTPRequest::RequestMethod m);
+
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
evhttp_request* evreq = evhttp_request_new(nullptr, nullptr);
assert(evreq != nullptr);
diff --git a/src/test/httpserver_tests.cpp b/src/test/httpserver_tests.cpp
index 030d48db..75c25caf 100644
--- a/src/test/httpserver_tests.cpp
+++ b/src/test/httpserver_tests.cpp
@@ -12,6 +12,7 @@ BOOST_FIXTURE_TEST_SUITE(httpserver_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(test_query_parameters)
{
+ using http_libevent::GetQueryParameterFromUri;
std::string uri {};
// No parameters
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.