28 void StaticHandler::onRequest(std::unique_ptr<HTTPMessage> headers)
noexcept {
32 .
body(
"Only GET is supported")
40 file_ = std::make_unique<folly::File>(headers->getPath().c_str() + 1);
41 }
catch (
const std::system_error& ex) {
44 .
body(folly::to<std::string>(
"Could not find ", headers->getPath(),
53 readFileScheduled_ =
true;
61 while (file_ && !paused_) {
67 VLOG(4) <<
"Read error=" << rc;
70 LOG(
ERROR) <<
"Error reading file";
71 downstream_->sendAbort();
77 VLOG(4) <<
"Read EOF";
95 readFileScheduled_ =
false;
96 if (!checkForCompletion() && !paused_) {
97 VLOG(4) <<
"Resuming deferred readFile";
105 VLOG(4) <<
"StaticHandler paused";
110 VLOG(4) <<
"StaticHandler resumed";
113 if (!readFileScheduled_ && file_) {
114 readFileScheduled_ =
true;
119 VLOG(4) <<
"Deferred scheduling readFile";
124 void StaticHandler::onBody(std::unique_ptr<folly::IOBuf> )
noexcept {
138 checkForCompletion();
144 checkForCompletion();
147 bool StaticHandler::checkForCompletion() {
148 if (finished_ && !readFileScheduled_) {
149 VLOG(4) <<
"deleting StaticHandler";
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
ResponseBuilder & status(uint16_t code, const std::string &message)
fbstring exceptionStr(const std::exception &e)
constexpr detail::Map< Move > move
EventBase * getEventBase()
ssize_t readNoInt(int fd, void *buf, size_t count)
std::unique_ptr< folly::IOBuf > move()
ResponseBuilder & body(std::unique_ptr< folly::IOBuf > bodyIn)
requires E e noexcept(noexcept(s.error(std::move(e))))
static EventBaseManager * get()
std::pair< void *, std::size_t > preallocate(std::size_t min, std::size_t newAllocationSize, std::size_t max=std::numeric_limits< std::size_t >::max())
bool runInEventBaseThread(void(*fn)(T *), T *arg)
std::shared_ptr< Executor > getCPUExecutor()
int bind(NetworkSocket s, const sockaddr *name, socklen_t namelen)
void postallocate(std::size_t n)
static constexpr uint64_t data[1]