diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-05-08 07:58:50 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-05-08 07:58:50 +0000 |
| commit | b57b75f98dcc71de3bc0a767b01e3301b2a7f66e (patch) | |
| tree | 4d4c314d127b78ac81edd299b0e7ede01b04b5b6 /src/HttpServer.cc | |
| parent | 3a81b3c3d7cd9825d24ed548c707514f03ba0ba5 (diff) | |
2009-05-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added xml-rpc functionality. Currently only addURI commad is
supported. To enable xml-rpc, run aria2 with
--enable-http-server. This option name is temporal and will be
changed. The feature that reports download progress in html format
is temporarily disabled.
* src/HttpServer.cc
* src/HttpServer.h
* src/HttpServerBodyCommand.cc
* src/HttpServerBodyCommand.h
* src/HttpServerCommand.cc
* src/HttpServerResponseCommand.cc
* src/Makefile.am
* src/OptionParser.cc
* src/OptionParser.h
* src/RequestGroupMan.cc
* src/RequestGroupMan.h
* src/XmlRpcMethod.cc
* src/XmlRpcMethod.h
* src/XmlRpcMethodFactory.cc
* src/XmlRpcMethodFactory.h
* src/XmlRpcMethodImpl.cc
* src/XmlRpcMethodImpl.h
* src/download_helper.cc
* src/download_helper.h
* test/Makefile.am
* test/XmlRpcMethodTest.cc
Diffstat (limited to 'src/HttpServer.cc')
| -rw-r--r-- | src/HttpServer.cc | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/HttpServer.cc b/src/HttpServer.cc index cae0a076..70b5e00b 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -33,6 +33,9 @@ */ /* copyright --> */ #include "HttpServer.h" + +#include <sstream> + #include "HttpHeader.h" #include "SocketCore.h" #include "HttpHeaderProcessor.h" @@ -50,7 +53,8 @@ HttpServer::HttpServer(const SharedHandle<SocketCore>& socket, _socketBuffer(socket), _e(e), _headerProcessor(new HttpHeaderProcessor()), - _logger(LogFactory::getInstance()) + _logger(LogFactory::getInstance()), + _keepAlive(true) {} HttpServer::~HttpServer() {} @@ -77,14 +81,48 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest() _logger->info("HTTP Server received request\n%s", _headerProcessor->getHeaderString().c_str()); _lastRequestHeader = header; + _lastBody.clear(); + _lastBody.str(""); + _lastContentLength = + _lastRequestHeader->getFirstAsUInt(HttpHeader::CONTENT_LENGTH); _headerProcessor->clear(); } return header; } +bool HttpServer::receiveBody() +{ + if(_lastContentLength == 0) { + return true; + } + const size_t BUFLEN = 4096; + char buf[BUFLEN]; + size_t length = std::min(BUFLEN, _lastContentLength-_lastBody.tellg()); + _socket->readData(buf, length); + if(length == 0 && !(_socket->wantRead() || _socket->wantWrite())) { + throw DlAbortEx(EX_EOF_FROM_PEER); + } + _lastBody.write(buf, length); + return _lastContentLength == static_cast<uint64_t>(_lastBody.tellp()); +} + +std::string HttpServer::getBody() const +{ + return _lastBody.str(); +} + +const std::string& HttpServer::getRequestPath() const +{ + return _lastRequestHeader->getRequestPath(); +} + bool HttpServer::supportsPersistentConnection() const { + if(!_keepAlive) { + return false; + } + std::string connection = Util::toLower(_lastRequestHeader->getFirst(HttpHeader::CONNECTION)); @@ -93,10 +131,10 @@ bool HttpServer::supportsPersistentConnection() const connection.find("keep-alive") != std::string::npos); } -void HttpServer::feedResponse(const std::string& text) +void HttpServer::feedResponse(const std::string& text, const std::string& contentType) { std::string header = "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" + "Content-Type: "+contentType+"\r\n" "Content-Length: "+Util::uitos(text.size())+"\r\n"; if(!supportsPersistentConnection()) { |
