void HttpConnectionHandler::handle( int socketFD ) { std::string requestString = socketReader_.readToEnd( socketFD ); HttpRequest* request = parser_.parse( requestString ); HttpRequestHandler* handler = factory_.createHandler( *request ); HttpResponse* response = handler->handle( *request ); delete request; writer_.write( socketFD, *response ); delete response; delete handler; }
void ServiceThread::threadRun() { Logger::Info("Service thread %s started", m_url.c_str()); s_service_threads.set(this); Hdf hdf; hdf["get"] = 1; hdf["url"] = m_url; hdf["remote_host"] = RuntimeOption::ServerIP; ReplayTransport rt; rt.replayInput(hdf); HttpRequestHandler handler; handler.disablePathTranslation(); handler.handleRequest(&rt); Logger::Info("Service thread %s stopped", m_url.c_str()); }
void process() { HttpRequestHandler handler; for (unsigned int i = 0; i < 100; i++) { handler.handleRequest(this); } }
HttpServer::HttpServer() : m_stopped(false), m_loggerThread(this, &HttpServer::flushLog), m_watchDog(this, &HttpServer::watchDog) { // enabling mutex profiling, but it's not turned on LockProfiler::s_pfunc_profile = server_stats_log_mutex; if (RuntimeOption::TakeoverFilename.empty()) { m_pageServer = ServerPtr (new TypedServer<LibEventServer, HttpRequestHandler> (RuntimeOption::ServerIP, RuntimeOption::ServerPort, RuntimeOption::ServerThreadCount, RuntimeOption::RequestTimeoutSeconds)); } else { LibEventServerWithTakeover* server = (new TypedServer<LibEventServerWithTakeover, HttpRequestHandler> (RuntimeOption::ServerIP, RuntimeOption::ServerPort, RuntimeOption::ServerThreadCount, RuntimeOption::RequestTimeoutSeconds)); server->setTransferFilename(RuntimeOption::TakeoverFilename); server->addTakeoverListener(this); m_pageServer = ServerPtr(server); } m_adminServer = ServerPtr (new TypedServer<LibEventServer, AdminRequestHandler> (RuntimeOption::ServerIP, RuntimeOption::AdminServerPort, RuntimeOption::AdminThreadCount, RuntimeOption::RequestTimeoutSeconds)); for (unsigned int i = 0; i < RuntimeOption::SatelliteServerInfos.size(); i++) { SatelliteServerInfoPtr info = RuntimeOption::SatelliteServerInfos[i]; SatelliteServerPtr satellite = SatelliteServer::Create(info); if (satellite) { if (info->getType() == SatelliteServer::KindOfDanglingPageServer) { m_danglings.push_back(satellite); } else { m_satellites.push_back(satellite); } } } if (RuntimeOption::EnableStaticContentCache) { StaticContentCache::TheCache.load(); } ClassInfo::Load(); SourceInfo::TheSourceInfo.load(); RTTIInfo::TheRTTIInfo.init(true); hphp_process_init(); apc_load(RuntimeOption::ApcLoadThread); Server::InstallStopSignalHandlers(m_pageServer); Server::InstallStopSignalHandlers(m_adminServer); if (!RuntimeOption::StartupDocument.empty()) { Hdf hdf; hdf["get"] = 1; hdf["url"] = RuntimeOption::StartupDocument; hdf["remote_host"] = RuntimeOption::ServerIP; ReplayTransport rt; rt.replayInput(hdf); HttpRequestHandler handler; handler.handleRequest(&rt); int code = rt.getResponseCode(); if (code == 200) { Logger::Info("StartupDocument %s returned 200 OK: %s", RuntimeOption::StartupDocument.c_str(), rt.getResponse().c_str()); } else { Logger::Error("StartupDocument %s failed %d: %s", RuntimeOption::StartupDocument.c_str(), code, rt.getResponse().data()); return; } } for (unsigned int i = 0; i < RuntimeOption::ThreadDocuments.size(); i++) { ServiceThreadPtr thread (new ServiceThread(RuntimeOption::ThreadDocuments[i])); m_serviceThreads.push_back(thread); } }