/* */ #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" #include "XmlRpcResponse.h" #include "DownloadContext.h" #include "wallclock.h" #include "util.h" #include "ServerStatMan.h" #include "FileAllocationEntry.h" #include "CheckIntegrityEntry.h" namespace aria2 { HttpServerBodyCommand::HttpServerBodyCommand (cuid_t cuid, const SharedHandle& httpServer, DownloadEngine* e, const SharedHandle& socket): Command(cuid), e_(e), socket_(socket), httpServer_(httpServer) { setStatus(Command::STATUS_ONESHOT_REALTIME); e_->addSocketForReadCheck(socket_, this); } HttpServerBodyCommand::~HttpServerBodyCommand() { e_->deleteSocketForReadCheck(socket_, this); } bool HttpServerBodyCommand::execute() { if(e_->getRequestGroupMan()->downloadFinished() || e_->isHaltRequested()) { return true; } try { if(socket_->isReadable(0) || httpServer_->getContentLength() == 0) { timeoutTimer_ = global::wallclock; if(httpServer_->receiveBody()) { // Do something for requestpath and body if(httpServer_->getRequestPath() == "/rpc") { xmlrpc::XmlRpcRequest req = xmlrpc::XmlRpcRequestProcessor().parseMemory(httpServer_->getBody()); SharedHandle method = xmlrpc::XmlRpcMethodFactory::create(req.methodName); xmlrpc::XmlRpcResponse res = method->execute(req, e_); bool gzip = httpServer_->supportsGZip(); std::string responseData = res.toXml(gzip); httpServer_->feedResponse(responseData, "text/xml"); Command* command = new HttpServerResponseCommand(getCuid(), httpServer_, e_, socket_); e_->addCommand(command); e_->setNoWait(true); return true; } else { return true; } } else { e_->addCommand(this); return false; } } else { if(timeoutTimer_.difference(global::wallclock) >= 30) { getLogger()->info("HTTP request body timeout."); return true; } else { e_->addCommand(this); return false; } } } catch(RecoverableException& e) { if(getLogger()->info()) { getLogger()->info ("CUID#%s - Error occurred while reading HTTP request body", e, util::itos(getCuid()).c_str()); } return true; } } } // namespace aria2