mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-17 13:22:03 +01:00
http: enclose libevent-dependent code in a namespace
This commit is a no-op to isolate HTTP methods and objects that depend on libevent. Following commits will add replacement objects and methods in a new namespace for testing and review before switching over the server.
This commit is contained in:
parent
a7db47d592
commit
a31b62f926
@ -26,6 +26,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using http_libevent::HTTPRequest;
|
||||
using util::SplitString;
|
||||
using util::TrimStringView;
|
||||
|
||||
|
@ -43,6 +43,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;
|
||||
@ -438,6 +439,7 @@ static void libevent_log_cb(int severity, const char *msg)
|
||||
LogPrintLevel(BCLog::LIBEVENT, level, "%s\n", msg);
|
||||
}
|
||||
|
||||
namespace http_libevent {
|
||||
bool InitHTTPServer(const util::SignalInterrupt& interrupt)
|
||||
{
|
||||
if (!InitHTTPAllowList())
|
||||
@ -559,6 +561,7 @@ void StopHTTPServer()
|
||||
g_work_queue.reset();
|
||||
LogDebug(BCLog::HTTP, "Stopped HTTP server\n");
|
||||
}
|
||||
} // namespace http_libevent
|
||||
|
||||
struct event_base* EventBase()
|
||||
{
|
||||
@ -591,6 +594,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)
|
||||
{
|
||||
@ -753,6 +758,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)
|
||||
{
|
||||
|
@ -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<bool(HTTPRequest* req, const std::string &)> HTTPRequestHandler;
|
||||
typedef std::function<bool(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.
|
||||
@ -64,6 +67,7 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch);
|
||||
*/
|
||||
struct event_base* EventBase();
|
||||
|
||||
namespace http_libevent {
|
||||
/** In-flight HTTP request.
|
||||
* Thin C++ wrapper around evhttp_request.
|
||||
*/
|
||||
@ -145,6 +149,7 @@ public:
|
||||
void WriteReply(int nStatus, std::span<const std::byte> reply);
|
||||
};
|
||||
|
||||
|
||||
/** Get the query parameter value from request uri for a specified key, or std::nullopt if the key
|
||||
* is not found.
|
||||
*
|
||||
@ -158,6 +163,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 handler closure.
|
||||
*/
|
||||
|
@ -121,6 +121,10 @@ using common::AmountErrMsg;
|
||||
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;
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
using http_libevent::HTTPRequest;
|
||||
using node::GetTransaction;
|
||||
using node::NodeContext;
|
||||
using util::SplitString;
|
||||
|
@ -256,7 +256,7 @@ static RPCHelpMan 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);
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using http_libevent::HTTPRequest;
|
||||
|
||||
extern "C" int evhttp_parse_firstline_(struct evhttp_request*, struct evbuffer*);
|
||||
extern "C" int evhttp_parse_headers_(struct evhttp_request*, struct evbuffer*);
|
||||
|
||||
|
@ -11,6 +11,7 @@ BOOST_FIXTURE_TEST_SUITE(httpserver_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_query_parameters)
|
||||
{
|
||||
using http_libevent::GetQueryParameterFromUri;
|
||||
std::string uri {};
|
||||
|
||||
// No parameters
|
||||
|
Loading…
x
Reference in New Issue
Block a user