Add helper methods to HTTPRequest to match original API

These methods are called by http_request_cb() and are present in the
original http_libevent::HTTPRequest.
This commit is contained in:
Matthew Zipkin
2024-12-12 11:44:52 -05:00
parent dd11b5e01b
commit f946ff5a0b
3 changed files with 116 additions and 12 deletions

View File

@@ -322,6 +322,16 @@ public:
{
WriteReply(status, std::as_bytes(std::span{reply_body_view}));
}
// These methods reimplement the API from http_libevent::HTTPRequest
// for downstream JSONRPC and REST modules.
std::string GetURI() const { return m_target; }
CService GetPeer() const;
HTTPRequestMethod GetRequestMethod() const { return m_method; }
std::optional<std::string> GetQueryParameter(std::string_view key) const;
std::pair<bool, std::string> GetHeader(std::string_view hdr) const;
std::string ReadBody() const { return m_body; }
void WriteHeader(std::string&& hdr, std::string&& value);
};
class HTTPServer
@@ -520,6 +530,8 @@ private:
void DisconnectClients();
};
std::optional<std::string> GetQueryParameterFromUri(std::string_view uri, std::string_view key);
class HTTPRemoteClient
{
public: