Commit b08fdb9a authored by Ian Roddis's avatar Ian Roddis

Changing the char* to const, adding example streaming binary path in http_server example

parent b26f13de
...@@ -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,7 +316,7 @@ public: ...@@ -316,7 +316,7 @@ public:
friend friend
ResponseStream& operator<<(ResponseStream& stream, const T& val); ResponseStream& operator<<(ResponseStream& stream, const T& val);
std::streamsize write(char * data, std::streamsize sz) { std::streamsize write(const char * data, std::streamsize sz) {
std::ostream os(&buf_); std::ostream os(&buf_);
os << std::hex << sz << crlf; os << std::hex << sz << crlf;
os.write(data, sz); os.write(data, sz);
......
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