Add ERR_END_OF_STREAM

Add new error code "END_OF_STREAM" and use it in HttpStreamParser.
Update a test to expect failure instead of success on an incomplete stream.

BUG=25032
TEST=updated unittests

Review URL: http://codereview.chromium.org/650190

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39822 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index edc519ab..0f66188e 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -956,13 +956,11 @@
   }
 
   if (result == ERR_CONNECTION_CLOSED) {
+    // For now, if we get at last some data, we do the best we can to make
+    // sense of it and send it back up the stack.
     int rv = HandleConnectionClosedBeforeEndOfHeaders();
     if (rv != OK)
       return rv;
-    // TODO(wtc): Traditionally this code has returned 0 when reading a closed
-    // socket.  That is partially corrected in classes that we call, but
-    // callers need to be updated.
-    result = 0;
   }
 
   if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) {
@@ -1062,11 +1060,16 @@
     // TODO(wtc): Traditionally this code has returned 0 when reading a closed
     // socket.  That is partially corrected in classes that we call, but
     // callers need to be updated.
-    if (result == ERR_CONNECTION_CLOSED)
+    if (result == ERR_END_OF_STREAM || (!http_stream_->CanFindEndOfResponse() &&
+                                        result == ERR_CONNECTION_CLOSED)) {
       result = 0;
-  } else if (http_stream_->IsResponseBodyComplete()) {
+    }
+  }
+
+  if (http_stream_->IsResponseBodyComplete()) {
     done = true;
-    keep_alive = GetResponseHeaders()->IsKeepAlive();
+    if (http_stream_->CanFindEndOfResponse())
+        keep_alive = GetResponseHeaders()->IsKeepAlive();
   }
 
   // Clean up connection_->if we are done.