// }}} // {{{ backends bool ApiRequest::processBackend() { Director* director = findDirector(tokens_[0]); if (!director) { request_->status = x0::HttpStatus::NotFound; request_->finish(); return true; } switch (requestMethod()) { case HttpMethod::GET: return show(director->findBackend(tokens_[2].str())); case HttpMethod::POST: return update(director->findBackend(tokens_[2].str()), director); case HttpMethod::UNLOCK: return lock(false, director->findBackend(tokens_[2].str()), director); case HttpMethod::LOCK: return lock(true, director->findBackend(tokens_[2].str()), director); case HttpMethod::DELETE: return destroy(director->findBackend(tokens_[2].str()), director); default: return false; } }
void DirectorPlugin::pass(HttpRequest* r, const std::string& directorName, const std::string& backendName) { auto i = directors_.find(directorName); if (i == directors_.end()) { r->log(Severity::error, "director.pass(): No director with name '%s' configured.", directorName.c_str()); internalServerError(r); return; } Director* director = i->second.get(); // custom backend route Backend* backend = nullptr; if (!backendName.empty()) { backend = director->findBackend(backendName); if (!backend) { // explicit backend specified, but not found -> do not serve. r->log(Severity::error, "director: Requested backend '%s' not found.", backendName.c_str()); internalServerError(r); return; } } #if !defined(NDEBUG) server().log(Severity::trace, "director: passing request to %s [backend %s].", director->name().c_str(), backend->name().c_str()); #endif auto rn = requestNotes(r); rn->manager = director; r->onPostProcess.connect(std::bind(&DirectorPlugin::addVia, this, r)); director->schedule(rn, backend); return; }