summaryrefslogtreecommitdiff
path: root/src/HttpServer.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-01-22 14:09:39 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-01-22 14:09:39 +0000
commit06a52cad02bec8740eaaf357f3404d241136f830 (patch)
tree440492a6602b15b7d74e02fc7d10023dab566049 /src/HttpServer.cc
parent5d8864caedd849ed98fbdb86282124b2b47e6090 (diff)
2010-01-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
aria2 now returns gzip compressed XML-RPC response if XML-RPC client accepts gzip content encoding. * src/A2STR.cc * src/A2STR.h * src/GZipEncoder.cc * src/GZipEncoder.h * src/HttpHeader.cc * src/HttpHeader.h * src/HttpServer.cc * src/HttpServer.h * src/HttpServerBodyCommand.cc * src/HttpServerCommand.cc * src/Makefile.am * src/XmlRpcResponse.cc * src/XmlRpcResponse.h * test/GZipEncoderTest.cc * test/Makefile.am
Diffstat (limited to 'src/HttpServer.cc')
-rw-r--r--src/HttpServer.cc38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/HttpServer.cc b/src/HttpServer.cc
index 12ad34a2..16efce3c 100644
--- a/src/HttpServer.cc
+++ b/src/HttpServer.cc
@@ -56,7 +56,10 @@ HttpServer::HttpServer(const SharedHandle<SocketCore>& socket,
_e(e),
_headerProcessor(new HttpHeaderProcessor()),
_logger(LogFactory::getInstance()),
- _keepAlive(true)
+ _keepAlive(true),
+ _gzip(false),
+ _acceptsPersistentConnection(true),
+ _acceptsGZip(false)
{}
HttpServer::~HttpServer() {}
@@ -88,8 +91,21 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest()
_lastContentLength =
_lastRequestHeader->getFirstAsUInt(HttpHeader::CONTENT_LENGTH);
_headerProcessor->clear();
- }
+ std::string connection =
+ util::toLower(_lastRequestHeader->getFirst(HttpHeader::CONNECTION));
+ _acceptsPersistentConnection =
+ connection.find(HttpHeader::CLOSE) == std::string::npos &&
+ (_lastRequestHeader->getVersion() == HttpHeader::HTTP_1_1 ||
+ connection.find("keep-alive") != std::string::npos);
+
+ std::vector<std::string> acceptEncodings;
+ util::split(_lastRequestHeader->getFirst(HttpHeader::ACCEPT_ENCODING),
+ std::back_inserter(acceptEncodings), A2STR::COMMA_C, true);
+ _acceptsGZip =
+ std::find(acceptEncodings.begin(), acceptEncodings.end(), "gzip")
+ != acceptEncodings.end();
+ }
return header;
}
@@ -121,20 +137,6 @@ 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));
-
- return connection.find(HttpHeader::CLOSE) == std::string::npos &&
- (_lastRequestHeader->getVersion() == HttpHeader::HTTP_1_1 ||
- connection.find("keep-alive") != std::string::npos);
-}
-
void HttpServer::feedResponse(const std::string& text, const std::string& contentType)
{
feedResponse("200 OK", "", text, contentType);
@@ -149,7 +151,9 @@ void HttpServer::feedResponse(const std::string& status,
strappend(header, status, "\r\n",
"Content-Type: ", contentType, "\r\n",
"Content-Length: ", util::uitos(text.size()), "\r\n");
-
+ if(supportsGZip()) {
+ header += "Content-Encoding: gzip\r\n";
+ }
if(!supportsPersistentConnection()) {
header += "Connection: close\r\n";
}