/* */ #include "HttpServerBodyCommand.h" #include "SocketCore.h" #include "DownloadEngine.h" #include "HttpServer.h" #include "HttpHeader.h" #include "Logger.h" #include "RequestGroup.h" #include "RequestGroupMan.h" #include "RecoverableException.h" #include "HttpServerResponseCommand.h" #include "OptionParser.h" #include "OptionHandler.h" #include "XmlRpcRequestProcessor.h" #include "XmlRpcRequestParserStateMachine.h" #include "XmlRpcMethod.h" #include "XmlRpcMethodFactory.h" namespace aria2 { HttpServerBodyCommand::HttpServerBodyCommand (int32_t cuid, const SharedHandle& httpServer, DownloadEngine* e, const SharedHandle& socket): Command(cuid), _e(e), _socket(socket), _httpServer(httpServer) { _e->addSocketForReadCheck(_socket, this); } HttpServerBodyCommand::~HttpServerBodyCommand() { _e->deleteSocketForReadCheck(_socket, this); } bool HttpServerBodyCommand::execute() { if(_e->_requestGroupMan->downloadFinished() || _e->isHaltRequested()) { return true; } if(_socket->isReadable(0)) { _timeout.reset(); try { if(_httpServer->receiveBody()) { // Do something for requestpath and body if(_httpServer->getRequestPath() == "/rpc") { // For xml-rpc, disable keep-alive //_httpServer->disableKeepAlive(); xmlrpc::XmlRpcRequest req = xmlrpc::XmlRpcRequestProcessor().parseMemory(_httpServer->getBody()); SharedHandle method = xmlrpc::XmlRpcMethodFactory::create(req._methodName); std::string response = method->execute(req, _e); _httpServer->feedResponse(response, "text/xml"); Command* command = new HttpServerResponseCommand(cuid, _httpServer, _e, _socket); command->setStatus(Command::STATUS_ONESHOT_REALTIME); _e->commands.push_back(command); _e->setNoWait(true); return true; } else { return true; } } else { _e->commands.push_back(this); return false; } } catch(RecoverableException& e) { logger->info("CUID#%d - Error occurred while reading HTTP request body", e, cuid); return true; } } else { if(_timeout.elapsed(30)) { logger->info("HTTP request body timeout."); return true; } else { _e->commands.push_back(this); return false; } } } } // namespace aria2