example_clock building and working
This commit is contained in:
30
firesse.cc
Normal file
30
firesse.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "firesse.h"
|
||||
|
||||
namespace firesse {
|
||||
|
||||
Server::Server(int port, const std::function<void(std::unique_ptr<Stream>)>& callback)
|
||||
: callback_(callback),
|
||||
firecgi_server_(port,
|
||||
[this](std::unique_ptr<firecgi::Request> request) { OnRequest(std::move(request)); },
|
||||
1,
|
||||
{"HTTP_ACCEPT"}) {}
|
||||
|
||||
void Server::Serve() {
|
||||
firecgi_server_.Serve();
|
||||
}
|
||||
|
||||
void Server::OnRequest(std::unique_ptr<firecgi::Request> request) {
|
||||
if (request->GetParam("HTTP_ACCEPT") != "text/event-stream") {
|
||||
LOG(WARNING) << "bad HTTP_ACCEPT: " << request->GetParam("HTTP_ACCEPT");
|
||||
request->WriteHeader("Status", "400 Bad Request");
|
||||
request->WriteHeader("Content-Type", "text-plain");
|
||||
request->WriteBody("No \"Accept: text/event-stream\" header found in request. Please call this endpoint using EventSource.");
|
||||
request->End();
|
||||
return;
|
||||
}
|
||||
request->WriteHeader("Content-Type", "text/event-stream");
|
||||
request->WriteBody("");
|
||||
callback_(std::make_unique<Stream>(std::move(request)));
|
||||
}
|
||||
|
||||
} // namespace firesse
|
||||
Reference in New Issue
Block a user