Added overload for ResponseWriter::send for raw byte stream...

parent eb4114c8
pistache (0.0.001-git20191031-kip1) eoan; urgency=medium
* Latest upstream and first build for eoan.
-- Kip Warner <kip@thevertigo.com> Thu, 31 Oct 2019 18:23:04 -0700
pistache (0.0.001-git20191017-kip1) disco; urgency=medium pistache (0.0.001-git20191017-kip1) disco; urgency=medium
* Latest upstream. * Latest upstream.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <string> #include <string>
#include <cstddef>
#include <sys/timerfd.h> #include <sys/timerfd.h>
...@@ -500,13 +501,14 @@ public: ...@@ -500,13 +501,14 @@ public:
code_ = Http::Code::Method_Not_Allowed; code_ = Http::Code::Method_Not_Allowed;
headers_.add(std::make_shared<Http::Header::Allow>(supportedMethods)); headers_.add(std::make_shared<Http::Header::Allow>(supportedMethods));
std::string body = codeString(Pistache::Http::Code::Method_Not_Allowed); std::string body = codeString(Pistache::Http::Code::Method_Not_Allowed);
return putOnWire(body.c_str(), body.size()); return putOnWire(reinterpret_cast<const std::byte *>(body.c_str()), body.size());
} }
Async::Promise<ssize_t> send(Code code) { Async::Promise<ssize_t> send(Code code) {
code_ = code; code_ = code;
return putOnWire(nullptr, 0); return putOnWire(nullptr, 0);
} }
Async::Promise<ssize_t> send( Async::Promise<ssize_t> send(
Code code, Code code,
const std::string& body, const std::string& body,
...@@ -522,7 +524,7 @@ public: ...@@ -522,7 +524,7 @@ public:
headers_.add(std::make_shared<Header::ContentType>(mime)); headers_.add(std::make_shared<Header::ContentType>(mime));
} }
return putOnWire(body.c_str(), body.size()); return putOnWire(reinterpret_cast<const std::byte *>(body.c_str()), body.size());
} }
template<size_t N> template<size_t N>
...@@ -530,6 +532,19 @@ public: ...@@ -530,6 +532,19 @@ public:
Code code, Code code,
const char (&arr)[N], const char (&arr)[N],
const Mime::MediaType& mime = Mime::MediaType()) const Mime::MediaType& mime = Mime::MediaType())
{
return send(
code,
reinterpret_cast<const std::byte *>(arr),
N - 1,
std::forward<const Mime::MediaType&>(mime));
}
Async::Promise<ssize_t> send(
Code code,
const std::byte *data,
const size_t size,
const Mime::MediaType& mime = Mime::MediaType())
{ {
/* @Refactor: code duplication */ /* @Refactor: code duplication */
code_ = code; code_ = code;
...@@ -542,7 +557,7 @@ public: ...@@ -542,7 +557,7 @@ public:
headers_.add(std::make_shared<Header::ContentType>(mime)); headers_.add(std::make_shared<Header::ContentType>(mime));
} }
return putOnWire(arr, N - 1); return putOnWire(data, size);
} }
ResponseStream stream(Code code, size_t streamSize = DefaultStreamSize) { ResponseStream stream(Code code, size_t streamSize = DefaultStreamSize) {
...@@ -609,7 +624,7 @@ private: ...@@ -609,7 +624,7 @@ private:
timeout_.associatePeer(peer_); timeout_.associatePeer(peer_);
} }
Async::Promise<ssize_t> putOnWire(const char* data, size_t len); Async::Promise<ssize_t> putOnWire(const std::byte* data, size_t len);
std::weak_ptr<Tcp::Peer> peer_; std::weak_ptr<Tcp::Peer> peer_;
DynamicStreamBuf buf_; DynamicStreamBuf buf_;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <ctime> #include <ctime>
#include <iomanip> #include <iomanip>
#include <unordered_map> #include <unordered_map>
#include <cstddef>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -639,7 +640,7 @@ ResponseStream::ends() { ...@@ -639,7 +640,7 @@ ResponseStream::ends() {
} }
Async::Promise<ssize_t> Async::Promise<ssize_t>
ResponseWriter::putOnWire(const char* data, size_t len) ResponseWriter::putOnWire(const std::byte* data, size_t len)
{ {
try { try {
std::ostream os(&buf_); std::ostream os(&buf_);
...@@ -666,7 +667,7 @@ ResponseWriter::putOnWire(const char* data, size_t len) ...@@ -666,7 +667,7 @@ ResponseWriter::putOnWire(const char* data, size_t len)
OUT(os << crlf); OUT(os << crlf);
if (len > 0) { if (len > 0) {
OUT(os.write(data, len)); OUT(os.write(reinterpret_cast<const char *>(data), len));
} }
auto buffer = buf_.buffer(); auto buffer = buf_.buffer();
......
VERSION_MAJOR 0 VERSION_MAJOR 0
VERSION_MINOR 0 VERSION_MINOR 0
VERSION_PATCH 001 VERSION_PATCH 001
VERSION_GIT_DATE 20191017 VERSION_GIT_DATE 20191031
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment