rest: don't copy data when sending binary response

Also, change `HTTPRequest::WriteReply` to accept `std::span`.
This commit is contained in:
Roman Zeyde
2024-06-22 11:46:10 +03:00
parent 538363738e
commit 1556d21599
3 changed files with 17 additions and 17 deletions

View File

@@ -7,6 +7,7 @@
#include <functional>
#include <optional>
#include <span>
#include <string>
namespace util {
@@ -123,12 +124,16 @@ public:
/**
* Write HTTP reply.
* nStatus is the HTTP status code to send.
* strReply is the body of the reply. Keep it empty to send a standard message.
* reply is the body of the reply. Keep it empty to send a standard message.
*
* @note Can be called only once. As this will give the request back to the
* main thread, do not call any other HTTPRequest methods after calling this.
*/
void WriteReply(int nStatus, const std::string& strReply = "");
void WriteReply(int nStatus, std::string_view reply = "")
{
WriteReply(nStatus, std::as_bytes(std::span{reply.data(), reply.size()}));
}
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