diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 16:35:23 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 16:35:23 +0000 |
commit | 5543cbb5dbebd81b40c0f9f30d2a007bab9abbc8 (patch) | |
tree | 215fbd66a8fa4a8a42282f47bb76826c2b34d8df /net/http | |
parent | a727dae7a83422afbb1051d1bb6666a4002f68c0 (diff) | |
download | chromium_src-5543cbb5dbebd81b40c0f9f30d2a007bab9abbc8.zip chromium_src-5543cbb5dbebd81b40c0f9f30d2a007bab9abbc8.tar.gz chromium_src-5543cbb5dbebd81b40c0f9f30d2a007bab9abbc8.tar.bz2 |
Report cases where the connection appears to close too early while transferring an HTTP body.
This should not change behavior at all, but will let us see how commonly these situations happen in the wild.
BUG=52847
TEST=Existing tests.
Review URL: http://codereview.chromium.org/9950023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133208 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_network_transaction_spdy2_unittest.cc | 2 | ||||
-rw-r--r-- | net/http/http_network_transaction_spdy3_unittest.cc | 2 | ||||
-rw-r--r-- | net/http/http_stream_parser.cc | 40 |
3 files changed, 36 insertions, 8 deletions
diff --git a/net/http/http_network_transaction_spdy2_unittest.cc b/net/http/http_network_transaction_spdy2_unittest.cc index e9ef256..fe0ff78 100644 --- a/net/http/http_network_transaction_spdy2_unittest.cc +++ b/net/http/http_network_transaction_spdy2_unittest.cc @@ -6341,7 +6341,7 @@ TEST_F(HttpNetworkTransactionSpdy2Test, LargeContentLengthThenClose) { std::string response_data; rv = ReadTransaction(trans.get(), &response_data); - EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); + EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); } TEST_F(HttpNetworkTransactionSpdy2Test, UploadFileSmallerThanLength) { diff --git a/net/http/http_network_transaction_spdy3_unittest.cc b/net/http/http_network_transaction_spdy3_unittest.cc index 4c73e94..c35def2 100644 --- a/net/http/http_network_transaction_spdy3_unittest.cc +++ b/net/http/http_network_transaction_spdy3_unittest.cc @@ -6341,7 +6341,7 @@ TEST_F(HttpNetworkTransactionSpdy3Test, LargeContentLengthThenClose) { std::string response_data; rv = ReadTransaction(trans.get(), &response_data); - EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); + EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); } TEST_F(HttpNetworkTransactionSpdy3Test, UploadFileSmallerThanLength) { diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc index 8098a18..31c7b73 100644 --- a/net/http/http_stream_parser.cc +++ b/net/http/http_stream_parser.cc @@ -662,12 +662,40 @@ int HttpStreamParser::DoReadBody() { } int HttpStreamParser::DoReadBodyComplete(int result) { - // If we didn't get a Content-Length and aren't using a chunked encoding, - // the only way to signal the end of a stream is to close the connection, - // so we don't treat that as an error, though in some cases we may not - // have completely received the resource. - if (result == 0 && !IsResponseBodyComplete() && CanFindEndOfResponse()) - result = ERR_CONNECTION_CLOSED; + // When the connection is closed, there are numerous ways to interpret it. + // + // - If a Content-Length header is present and the body contains exactly that + // number of bytes at connection close, the response is successful. + // + // - If a Content-Length header is present and the body contains fewer bytes + // than promised by the header at connection close, it may indicate that + // the connection was closed prematurely, or it may indicate that the + // server sent an invalid Content-Length header. Unfortunately, the invalid + // Content-Length header case does occur in practice and other browsers are + // tolerant of it. We choose to treat it as an error for now, but the + // download system treats it as a non-error, and URLRequestHttpJob also + // treats it as OK if the Content-Length is the post-decoded body content + // length. + // + // - If chunked encoding is used and the terminating chunk has been processed + // when the connection is closed, the response is successful. + // + // - If chunked encoding is used and the terminating chunk has not been + // processed when the connection is closed, it may indicate that the + // connection was closed prematurely or it may indicate that the server + // sent an invalid chunked encoding. We choose to treat it as + // an invalid chunked encoding. + // + // - If a Content-Length is not present and chunked encoding is not used, + // connection close is the only way to signal that the response is + // complete. Unfortunately, this also means that there is no way to detect + // early close of a connection. No error is returned. + if (result == 0 && !IsResponseBodyComplete() && CanFindEndOfResponse()) { + if (chunked_decoder_.get()) + result = ERR_INCOMPLETE_CHUNKED_ENCODING; + else + result = ERR_CONTENT_LENGTH_MISMATCH; + } // Filter incoming data if appropriate. FilterBuf may return an error. if (result > 0 && chunked_decoder_.get()) { |