mirror of https://github.com/aria2/aria2
Removed static std::string constant in HttpHeader
This change also removes inspection of Proxy-Connection header field when checking whether the remote endpoint keeps connection open.pull/28/head
parent
dd7014a612
commit
54665ff409
|
@ -41,13 +41,6 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
const std::string HttpHeader::HTTP_1_1 = "HTTP/1.1";
|
|
||||||
const std::string HttpHeader::CLOSE = "close";
|
|
||||||
const std::string HttpHeader::KEEP_ALIVE = "keep-alive";
|
|
||||||
const std::string HttpHeader::CHUNKED = "chunked";
|
|
||||||
const std::string HttpHeader::GZIP = "gzip";
|
|
||||||
const std::string HttpHeader::DEFLATE = "deflate";
|
|
||||||
|
|
||||||
HttpHeader::HttpHeader() {}
|
HttpHeader::HttpHeader() {}
|
||||||
HttpHeader::~HttpHeader() {}
|
HttpHeader::~HttpHeader() {}
|
||||||
|
|
||||||
|
@ -259,6 +252,13 @@ bool HttpHeader::fieldContains(int hdKey, const char* value)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HttpHeader::isKeepAlive() const
|
||||||
|
{
|
||||||
|
const std::string& connection = find(CONNECTION);
|
||||||
|
return !util::strieq(connection, "close") &&
|
||||||
|
(version_ == "HTTP/1.1" || util::strieq(connection, "keep-alive"));
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const char* INTERESTING_HEADER_NAMES[] = {
|
const char* INTERESTING_HEADER_NAMES[] = {
|
||||||
"accept-encoding",
|
"accept-encoding",
|
||||||
|
|
|
@ -158,12 +158,9 @@ public:
|
||||||
// assumes the values of the header field is delimited by ','.
|
// assumes the values of the header field is delimited by ','.
|
||||||
bool fieldContains(int hdKey, const char* value);
|
bool fieldContains(int hdKey, const char* value);
|
||||||
|
|
||||||
static const std::string HTTP_1_1;
|
// Returns true if the headers indicate that the remote endpoint
|
||||||
static const std::string CLOSE;
|
// keeps connection open.
|
||||||
static const std::string KEEP_ALIVE;
|
bool isKeepAlive() const;
|
||||||
static const std::string CHUNKED;
|
|
||||||
static const std::string GZIP;
|
|
||||||
static const std::string DEFLATE;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int idInterestingHeader(const char* hdName);
|
int idInterestingHeader(const char* hdName);
|
||||||
|
|
|
@ -197,7 +197,7 @@ SharedHandle<StreamFilter> HttpResponse::getTransferEncodingStreamFilter() const
|
||||||
// TODO Transfer-Encoding header field can contains multiple tokens. We should
|
// TODO Transfer-Encoding header field can contains multiple tokens. We should
|
||||||
// parse the field and retrieve each token.
|
// parse the field and retrieve each token.
|
||||||
if(isTransferEncodingSpecified()) {
|
if(isTransferEncodingSpecified()) {
|
||||||
if(getTransferEncoding() == HttpHeader::CHUNKED) {
|
if(util::strieq(getTransferEncoding(), "chunked")) {
|
||||||
filter.reset(new ChunkedDecodingStreamFilter());
|
filter.reset(new ChunkedDecodingStreamFilter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,8 +218,8 @@ SharedHandle<StreamFilter> HttpResponse::getContentEncodingStreamFilter() const
|
||||||
{
|
{
|
||||||
SharedHandle<StreamFilter> filter;
|
SharedHandle<StreamFilter> filter;
|
||||||
#ifdef HAVE_ZLIB
|
#ifdef HAVE_ZLIB
|
||||||
if(getContentEncoding() == HttpHeader::GZIP ||
|
if(util::strieq(getContentEncoding(), "gzip") ||
|
||||||
getContentEncoding() == HttpHeader::DEFLATE) {
|
util::strieq(getContentEncoding(), "deflate")) {
|
||||||
filter.reset(new GZipDecodingStreamFilter());
|
filter.reset(new GZipDecodingStreamFilter());
|
||||||
}
|
}
|
||||||
#endif // HAVE_ZLIB
|
#endif // HAVE_ZLIB
|
||||||
|
@ -288,25 +288,7 @@ Time HttpResponse::getLastModifiedTime() const
|
||||||
|
|
||||||
bool HttpResponse::supportsPersistentConnection() const
|
bool HttpResponse::supportsPersistentConnection() const
|
||||||
{
|
{
|
||||||
const std::string& connection = httpHeader_->find(HttpHeader::CONNECTION);
|
return httpHeader_->isKeepAlive();
|
||||||
const std::string& version = httpHeader_->getVersion();
|
|
||||||
const std::string& proxyConn =
|
|
||||||
httpHeader_->find(HttpHeader::PROXY_CONNECTION);
|
|
||||||
return
|
|
||||||
util::strifind(connection.begin(),
|
|
||||||
connection.end(),
|
|
||||||
HttpHeader::CLOSE.begin(),
|
|
||||||
HttpHeader::CLOSE.end()) == connection.end() &&
|
|
||||||
(version == HttpHeader::HTTP_1_1 ||
|
|
||||||
util::strifind(connection.begin(),
|
|
||||||
connection.end(),
|
|
||||||
HttpHeader::KEEP_ALIVE.begin(),
|
|
||||||
HttpHeader::KEEP_ALIVE.end()) != connection.end()) &&
|
|
||||||
(!httpRequest_->isProxyRequestSet() ||
|
|
||||||
util::strifind(proxyConn.begin(),
|
|
||||||
proxyConn.end(),
|
|
||||||
HttpHeader::KEEP_ALIVE.begin(),
|
|
||||||
HttpHeader::KEEP_ALIVE.end()) != proxyConn.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -71,7 +71,6 @@ HttpServer::HttpServer
|
||||||
reqType_(RPC_TYPE_NONE),
|
reqType_(RPC_TYPE_NONE),
|
||||||
keepAlive_(true),
|
keepAlive_(true),
|
||||||
gzip_(false),
|
gzip_(false),
|
||||||
acceptsPersistentConnection_(true),
|
|
||||||
acceptsGZip_(false)
|
acceptsGZip_(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -156,19 +155,6 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest()
|
||||||
}
|
}
|
||||||
headerProcessor_->clear();
|
headerProcessor_->clear();
|
||||||
|
|
||||||
const std::string& connection =
|
|
||||||
lastRequestHeader_->find(HttpHeader::CONNECTION);
|
|
||||||
acceptsPersistentConnection_ =
|
|
||||||
util::strifind(connection.begin(),
|
|
||||||
connection.end(),
|
|
||||||
HttpHeader::CLOSE.begin(),
|
|
||||||
HttpHeader::CLOSE.end()) == connection.end() &&
|
|
||||||
(lastRequestHeader_->getVersion() == HttpHeader::HTTP_1_1 ||
|
|
||||||
util::strifind(connection.begin(),
|
|
||||||
connection.end(),
|
|
||||||
HttpHeader::KEEP_ALIVE.begin(),
|
|
||||||
HttpHeader::KEEP_ALIVE.end()) != connection.end());
|
|
||||||
|
|
||||||
std::vector<Scip> acceptEncodings;
|
std::vector<Scip> acceptEncodings;
|
||||||
const std::string& acceptEnc =
|
const std::string& acceptEnc =
|
||||||
lastRequestHeader_->find(HttpHeader::ACCEPT_ENCODING);
|
lastRequestHeader_->find(HttpHeader::ACCEPT_ENCODING);
|
||||||
|
@ -177,8 +163,7 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest()
|
||||||
acceptsGZip_ = false;
|
acceptsGZip_ = false;
|
||||||
for(std::vector<Scip>::const_iterator i = acceptEncodings.begin(),
|
for(std::vector<Scip>::const_iterator i = acceptEncodings.begin(),
|
||||||
eoi = acceptEncodings.end(); i != eoi; ++i) {
|
eoi = acceptEncodings.end(); i != eoi; ++i) {
|
||||||
if(util::strieq((*i).first, (*i).second,
|
if(util::strieq((*i).first, (*i).second, "gzip")) {
|
||||||
HttpHeader::GZIP.begin(), HttpHeader::GZIP.end())) {
|
|
||||||
acceptsGZip_ = true;
|
acceptsGZip_ = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -392,4 +377,10 @@ std::string HttpServer::createQuery() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HttpServer::supportsPersistentConnection() const
|
||||||
|
{
|
||||||
|
return keepAlive_ &&
|
||||||
|
lastRequestHeader_ && lastRequestHeader_->isKeepAlive();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -80,7 +80,6 @@ private:
|
||||||
bool gzip_;
|
bool gzip_;
|
||||||
std::string username_;
|
std::string username_;
|
||||||
std::string password_;
|
std::string password_;
|
||||||
bool acceptsPersistentConnection_;
|
|
||||||
bool acceptsGZip_;
|
bool acceptsGZip_;
|
||||||
std::string allowOrigin_;
|
std::string allowOrigin_;
|
||||||
public:
|
public:
|
||||||
|
@ -138,10 +137,7 @@ public:
|
||||||
|
|
||||||
bool sendBufferIsEmpty() const;
|
bool sendBufferIsEmpty() const;
|
||||||
|
|
||||||
bool supportsPersistentConnection() const
|
bool supportsPersistentConnection() const;
|
||||||
{
|
|
||||||
return keepAlive_ && acceptsPersistentConnection_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool supportsGZip() const
|
bool supportsGZip() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -138,7 +138,7 @@ void HttpHeaderTest::testClearField()
|
||||||
{
|
{
|
||||||
HttpHeader h;
|
HttpHeader h;
|
||||||
h.setStatusCode(200);
|
h.setStatusCode(200);
|
||||||
h.setVersion(HttpHeader::HTTP_1_1);
|
h.setVersion("HTTP/1.1");
|
||||||
h.put(HttpHeader::LINK, "Bar");
|
h.put(HttpHeader::LINK, "Bar");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Bar"), h.find(HttpHeader::LINK));
|
CPPUNIT_ASSERT_EQUAL(std::string("Bar"), h.find(HttpHeader::LINK));
|
||||||
|
@ -147,7 +147,7 @@ void HttpHeaderTest::testClearField()
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""), h.find(HttpHeader::LINK));
|
CPPUNIT_ASSERT_EQUAL(std::string(""), h.find(HttpHeader::LINK));
|
||||||
CPPUNIT_ASSERT_EQUAL(200, h.getStatusCode());
|
CPPUNIT_ASSERT_EQUAL(200, h.getStatusCode());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(HttpHeader::HTTP_1_1), h.getVersion());
|
CPPUNIT_ASSERT_EQUAL(std::string("HTTP/1.1"), h.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpHeaderTest::testFieldContains()
|
void HttpHeaderTest::testFieldContains()
|
||||||
|
|
|
@ -581,20 +581,12 @@ void HttpResponseTest::testSupportsPersistentConnection()
|
||||||
httpRequest->setProxyRequest(proxyRequest);
|
httpRequest->setProxyRequest(proxyRequest);
|
||||||
|
|
||||||
httpHeader->setVersion("HTTP/1.1");
|
httpHeader->setVersion("HTTP/1.1");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "close");
|
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
||||||
httpHeader->clearField();
|
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
||||||
httpHeader->clearField();
|
|
||||||
httpHeader->put(HttpHeader::PROXY_CONNECTION, "keep-alive");
|
|
||||||
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "close");
|
httpHeader->put(HttpHeader::CONNECTION, "close");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpHeader->clearField();
|
||||||
httpHeader->put(HttpHeader::PROXY_CONNECTION, "close");
|
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpHeader->clearField();
|
||||||
|
|
||||||
httpHeader->setVersion("HTTP/1.0");
|
httpHeader->setVersion("HTTP/1.0");
|
||||||
|
@ -603,16 +595,8 @@ void HttpResponseTest::testSupportsPersistentConnection()
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpHeader->clearField();
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
||||||
httpHeader->put(HttpHeader::PROXY_CONNECTION, "keep-alive");
|
|
||||||
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpHeader->clearField();
|
||||||
httpHeader->put(HttpHeader::PROXY_CONNECTION, "keep-alive");
|
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
||||||
httpHeader->clearField();
|
|
||||||
httpHeader->put(HttpHeader::PROXY_CONNECTION, "close");
|
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
||||||
httpHeader->clearField();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponseTest::testGetMetalinKHttpEntries()
|
void HttpResponseTest::testGetMetalinKHttpEntries()
|
||||||
|
|
Loading…
Reference in New Issue