Unverified Commit 99cac24c authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #275 from iroddis/stream_write

Stream write
parents 438b8946 fc6e14f9
...@@ -121,6 +121,16 @@ class MyHandler : public Http::Handler { ...@@ -121,6 +121,16 @@ class MyHandler : public Http::Handler {
response.send(Http::Code::Method_Not_Allowed); response.send(Http::Code::Method_Not_Allowed);
} }
} }
else if (req.resource() == "/stream_binary") {
auto stream = response.stream(Http::Code::Ok);
char binary_data[] = "some \0\r\n data\n";
size_t chunk_size = 14;
for (size_t i = 0; i < 10; ++i) {
stream.write(binary_data, chunk_size);
stream.flush();
}
stream.ends();
}
else if (req.resource() == "/exception") { else if (req.resource() == "/exception") {
throw std::runtime_error("Exception thrown in the handler"); throw std::runtime_error("Exception thrown in the handler");
} }
......
...@@ -316,6 +316,14 @@ public: ...@@ -316,6 +316,14 @@ public:
friend friend
ResponseStream& operator<<(ResponseStream& stream, const T& val); ResponseStream& operator<<(ResponseStream& stream, const T& val);
std::streamsize write(const char * data, std::streamsize sz) {
std::ostream os(&buf_);
os << std::hex << sz << crlf;
os.write(data, sz);
os << crlf;
return sz;
}
const Header::Collection& headers() const { const Header::Collection& headers() const {
return headers_; return headers_;
} }
......
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