Disable HTTP pipelining if the connection closes.

Don’t keep attempting to pipeline if the next server sets Close on
its response, since this just generates needless overhead.
This commit is contained in:
James Turner
2016-03-22 20:06:22 +00:00
parent 2438dd8a08
commit 714a6ac47d
3 changed files with 25 additions and 2 deletions
+12 -2
View File
@@ -39,7 +39,8 @@ Request::Request(const std::string& url, const std::string method):
_responseLength(0),
_receivedBodyBytes(0),
_ready_state(UNSENT),
_willClose(false)
_willClose(false),
_connectionCloseHeader(false)
{
}
@@ -147,7 +148,10 @@ void Request::responseStart(const std::string& r)
void Request::responseHeader(const std::string& key, const std::string& value)
{
if( key == "connection" ) {
_willClose = (value.find("close") != std::string::npos);
_connectionCloseHeader = (value.find("close") != std::string::npos);
// track willClose seperately because other conditions (abort, for
// example) can also set it
_willClose = _connectionCloseHeader;
} else if (key == "content-length") {
int sz = strutils::to_int(value);
setResponseLength(sz);
@@ -380,6 +384,12 @@ bool Request::closeAfterComplete() const
return _willClose || (_responseVersion != HTTP_1_1);
}
//------------------------------------------------------------------------------
bool Request::serverSupportsPipelining() const
{
return (_responseVersion == HTTP_1_1) && !_connectionCloseHeader;
}
//------------------------------------------------------------------------------
bool Request::isComplete() const
{