2019-05-05 00:11:57 -07:00
|
|
|
#include "stream.h"
|
|
|
|
|
|
|
|
|
|
namespace firesse {
|
|
|
|
|
|
2019-05-07 23:26:48 -07:00
|
|
|
Stream::Stream(firecgi::Request* request)
|
|
|
|
|
: request_(request) {}
|
2019-05-05 00:11:57 -07:00
|
|
|
|
|
|
|
|
bool Stream::WriteEvent(const std::string& data, uint64_t id, const std::string& type) {
|
|
|
|
|
if (id) {
|
2019-05-09 23:23:09 -07:00
|
|
|
request_->WriteBody("id: ", std::to_string(id), "\n");
|
2019-05-05 00:11:57 -07:00
|
|
|
}
|
|
|
|
|
if (!type.empty()) {
|
2019-05-09 23:23:09 -07:00
|
|
|
request_->WriteBody("event: ", type, "\n");
|
2019-05-05 00:11:57 -07:00
|
|
|
}
|
2019-05-09 23:23:09 -07:00
|
|
|
request_->WriteBody("data: ", data, "\n");
|
2019-05-05 00:11:57 -07:00
|
|
|
|
|
|
|
|
return request_->Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Stream::End() {
|
|
|
|
|
return request_->End();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace firesse
|