mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-12 13:43:43 +01:00
rest: don't copy data when sending binary response
Also, change `HTTPRequest::WriteReply` to accept `std::span`.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -634,7 +635,7 @@ void HTTPRequest::WriteHeader(const std::string& hdr, const std::string& value)
|
||||
* Replies must be sent in the main loop in the main http thread,
|
||||
* this cannot be done from worker threads.
|
||||
*/
|
||||
void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
|
||||
void HTTPRequest::WriteReply(int nStatus, std::span<const std::byte> reply)
|
||||
{
|
||||
assert(!replySent && req);
|
||||
if (m_interrupt) {
|
||||
@@ -643,7 +644,7 @@ void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
|
||||
// Send event to main http thread to send reply message
|
||||
struct evbuffer* evb = evhttp_request_get_output_buffer(req);
|
||||
assert(evb);
|
||||
evbuffer_add(evb, strReply.data(), strReply.size());
|
||||
evbuffer_add(evb, reply.data(), reply.size());
|
||||
auto req_copy = req;
|
||||
HTTPEvent* ev = new HTTPEvent(eventBase, true, [req_copy, nStatus]{
|
||||
evhttp_send_reply(req_copy, nStatus, nullptr, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user