summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_basic_stream.cc6
-rw-r--r--net/http/http_basic_stream.h35
-rw-r--r--net/http/http_network_transaction.cc7
-rw-r--r--net/http/http_network_transaction_unittest.cc31
-rw-r--r--net/http/http_response_body_drainer_unittest.cc36
-rw-r--r--net/http/http_stream.h6
-rw-r--r--net/http/http_stream_parser.cc6
-rw-r--r--net/http/http_stream_parser.h4
8 files changed, 90 insertions, 41 deletions
diff --git a/net/http/http_basic_stream.cc b/net/http/http_basic_stream.cc
index ef4d777..6501a59 100644
--- a/net/http/http_basic_stream.cc
+++ b/net/http/http_basic_stream.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -102,6 +102,10 @@ void HttpBasicStream::SetConnectionReused() {
parser_->SetConnectionReused();
}
+bool HttpBasicStream::IsConnectionReusable() const {
+ return parser_->IsConnectionReusable();
+}
+
void HttpBasicStream::GetSSLInfo(SSLInfo* ssl_info) {
parser_->GetSSLInfo(ssl_info);
}
diff --git a/net/http/http_basic_stream.h b/net/http/http_basic_stream.h
index 2c26315..267c7c1 100644
--- a/net/http/http_basic_stream.h
+++ b/net/http/http_basic_stream.h
@@ -42,41 +42,44 @@ class HttpBasicStream : public HttpStream {
// HttpStream methods:
virtual int InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& net_log,
- CompletionCallback* callback);
+ CompletionCallback* callback) OVERRIDE;
virtual int SendRequest(const HttpRequestHeaders& headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- CompletionCallback* callback);
+ CompletionCallback* callback) OVERRIDE;
- virtual uint64 GetUploadProgress() const;
+ virtual uint64 GetUploadProgress() const OVERRIDE;
- virtual int ReadResponseHeaders(CompletionCallback* callback);
+ virtual int ReadResponseHeaders(CompletionCallback* callback) OVERRIDE;
- virtual const HttpResponseInfo* GetResponseInfo() const;
+ virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
virtual int ReadResponseBody(IOBuffer* buf, int buf_len,
- CompletionCallback* callback);
+ CompletionCallback* callback) OVERRIDE;
- virtual void Close(bool not_reusable);
+ virtual void Close(bool not_reusable) OVERRIDE;
- virtual HttpStream* RenewStreamForAuth();
+ virtual HttpStream* RenewStreamForAuth() OVERRIDE;
- virtual bool IsResponseBodyComplete() const;
+ virtual bool IsResponseBodyComplete() const OVERRIDE;
- virtual bool CanFindEndOfResponse() const;
+ virtual bool CanFindEndOfResponse() const OVERRIDE;
- virtual bool IsMoreDataBuffered() const;
+ virtual bool IsMoreDataBuffered() const OVERRIDE;
- virtual bool IsConnectionReused() const;
+ virtual bool IsConnectionReused() const OVERRIDE;
- virtual void SetConnectionReused();
+ virtual void SetConnectionReused() OVERRIDE;
- virtual void GetSSLInfo(SSLInfo* ssl_info);
+ virtual bool IsConnectionReusable() const OVERRIDE;
- virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info);
+ virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
- virtual bool IsSpdyHttpStream() const;
+ virtual void GetSSLCertRequestInfo(
+ SSLCertRequestInfo* cert_request_info) OVERRIDE;
+
+ virtual bool IsSpdyHttpStream() const OVERRIDE;
private:
scoped_refptr<GrowableIOBuffer> read_buf_;
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 46858e6..5cd2f92 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -273,7 +273,7 @@ void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) {
if (stream_.get()) {
HttpStream* new_stream = NULL;
- if (keep_alive) {
+ if (keep_alive && stream_->IsConnectionReusable()) {
// We should call connection_->set_idle_time(), but this doesn't occur
// often enough to be worth the trouble.
stream_->SetConnectionReused();
@@ -281,7 +281,10 @@ void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) {
}
if (!new_stream) {
- stream_->Close(!keep_alive);
+ // Close the stream and mark it as not_reusable. Even in the
+ // keep_alive case, we've determined that the stream_ is not
+ // reusable if new_stream is NULL.
+ stream_->Close(true);
next_state_ = STATE_CREATE_STREAM;
} else {
next_state_ = STATE_INIT_STREAM;
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 64d53ba..e11860c 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -1192,9 +1192,18 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) {
MockRead("Hello"),
};
+ // If there is a regression where we disconnect a Keep-Alive
+ // connection during an auth roundtrip, we'll end up reading this.
+ MockRead data_reads2[] = {
+ MockRead(false, ERR_FAILED),
+ };
+
StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
data_writes1, arraysize(data_writes1));
+ StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
+ NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data1);
+ session_deps.socket_factory.AddSocketDataProvider(&data2);
TestCompletionCallback callback1;
@@ -1224,7 +1233,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) {
EXPECT_EQ(OK, rv);
response = trans->GetResponseInfo();
- EXPECT_FALSE(response == NULL);
+ ASSERT_FALSE(response == NULL);
EXPECT_TRUE(response->auth_challenge.get() == NULL);
EXPECT_EQ(5, response->headers->GetContentLength());
}
@@ -1265,9 +1274,17 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) {
MockRead("hello"),
};
+ // An incorrect reconnect would cause this to be read.
+ MockRead data_reads2[] = {
+ MockRead(false, ERR_FAILED),
+ };
+
StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
data_writes1, arraysize(data_writes1));
+ StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
+ NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data1);
+ session_deps.socket_factory.AddSocketDataProvider(&data2);
TestCompletionCallback callback1;
@@ -1297,7 +1314,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) {
EXPECT_EQ(OK, rv);
response = trans->GetResponseInfo();
- EXPECT_FALSE(response == NULL);
+ ASSERT_FALSE(response == NULL);
EXPECT_TRUE(response->auth_challenge.get() == NULL);
EXPECT_EQ(5, response->headers->GetContentLength());
}
@@ -1346,9 +1363,17 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) {
MockRead("hello"),
};
+ // An incorrect reconnect would cause this to be read.
+ MockRead data_reads2[] = {
+ MockRead(false, ERR_FAILED),
+ };
+
StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
data_writes1, arraysize(data_writes1));
+ StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
+ NULL, 0);
session_deps.socket_factory.AddSocketDataProvider(&data1);
+ session_deps.socket_factory.AddSocketDataProvider(&data2);
TestCompletionCallback callback1;
@@ -1378,7 +1403,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) {
EXPECT_EQ(OK, rv);
response = trans->GetResponseInfo();
- EXPECT_FALSE(response == NULL);
+ ASSERT_FALSE(response == NULL);
EXPECT_TRUE(response->auth_challenge.get() == NULL);
EXPECT_EQ(5, response->headers->GetContentLength());
}
diff --git a/net/http/http_response_body_drainer_unittest.cc b/net/http/http_response_body_drainer_unittest.cc
index 9feed17..45c826e 100644
--- a/net/http/http_response_body_drainer_unittest.cc
+++ b/net/http/http_response_body_drainer_unittest.cc
@@ -74,44 +74,48 @@ class MockHttpStream : public HttpStream {
// HttpStream implementation:
virtual int InitializeStream(const HttpRequestInfo* request_info,
const BoundNetLog& net_log,
- CompletionCallback* callback) {
+ CompletionCallback* callback) OVERRIDE {
return ERR_UNEXPECTED;
}
virtual int SendRequest(const HttpRequestHeaders& request_headers,
UploadDataStream* request_body,
HttpResponseInfo* response,
- CompletionCallback* callback) {
+ CompletionCallback* callback) OVERRIDE {
return ERR_UNEXPECTED;
}
- virtual uint64 GetUploadProgress() const { return 0; }
- virtual int ReadResponseHeaders(CompletionCallback* callback) {
+ virtual uint64 GetUploadProgress() const OVERRIDE { return 0; }
+ virtual int ReadResponseHeaders(CompletionCallback* callback) OVERRIDE {
return ERR_UNEXPECTED;
}
- virtual const HttpResponseInfo* GetResponseInfo() const { return NULL; }
+ virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE {
+ return NULL;
+ }
- virtual bool CanFindEndOfResponse() const { return true; }
- virtual bool IsMoreDataBuffered() const { return false; }
- virtual bool IsConnectionReused() const { return false; }
- virtual void SetConnectionReused() {}
- virtual void GetSSLInfo(SSLInfo* ssl_info) {}
- virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) {}
+ virtual bool CanFindEndOfResponse() const OVERRIDE { return true; }
+ virtual bool IsMoreDataBuffered() const OVERRIDE { return false; }
+ virtual bool IsConnectionReused() const OVERRIDE { return false; }
+ virtual void SetConnectionReused() OVERRIDE {}
+ virtual bool IsConnectionReusable() const OVERRIDE { return false; }
+ virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE {}
+ virtual void GetSSLCertRequestInfo(
+ SSLCertRequestInfo* cert_request_info) OVERRIDE {}
// Mocked API
virtual int ReadResponseBody(IOBuffer* buf, int buf_len,
- CompletionCallback* callback);
- virtual void Close(bool not_reusable) {
+ CompletionCallback* callback) OVERRIDE;
+ virtual void Close(bool not_reusable) OVERRIDE {
DCHECK(!closed_);
closed_ = true;
result_waiter_->set_result(not_reusable);
}
- virtual HttpStream* RenewStreamForAuth() {
+ virtual HttpStream* RenewStreamForAuth() OVERRIDE {
return NULL;
}
- virtual bool IsResponseBodyComplete() const { return is_complete_; }
+ virtual bool IsResponseBodyComplete() const OVERRIDE { return is_complete_; }
- virtual bool IsSpdyHttpStream() const { return false; }
+ virtual bool IsSpdyHttpStream() const OVERRIDE { return false; }
// Methods to tweak/observer mock behavior:
void StallReadsForever() { stall_reads_forever_ = true; }
diff --git a/net/http/http_stream.h b/net/http/http_stream.h
index e262038..fed64655 100644
--- a/net/http/http_stream.h
+++ b/net/http/http_stream.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -116,6 +116,10 @@ class HttpStream {
virtual bool IsConnectionReused() const = 0;
virtual void SetConnectionReused() = 0;
+ // Checks whether the current state of the underlying connection
+ // allows it to be reused.
+ virtual bool IsConnectionReusable() const = 0;
+
// Get the SSLInfo associated with this stream's connection. This should
// only be called for streams over SSL sockets, otherwise the behavior is
// undefined.
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index eb1ed35..0649bce 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -700,6 +700,10 @@ void HttpStreamParser::SetConnectionReused() {
connection_->set_is_reused(true);
}
+bool HttpStreamParser::IsConnectionReusable() const {
+ return connection_->socket() && connection_->socket()->IsConnectedAndIdle();
+}
+
void HttpStreamParser::GetSSLInfo(SSLInfo* ssl_info) {
if (request_->url.SchemeIs("https") && connection_->socket()) {
SSLClientSocket* ssl_socket =
diff --git a/net/http/http_stream_parser.h b/net/http/http_stream_parser.h
index d9241a6..2192eff 100644
--- a/net/http/http_stream_parser.h
+++ b/net/http/http_stream_parser.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -67,6 +67,8 @@ class HttpStreamParser : public ChunkCallback {
void SetConnectionReused();
+ bool IsConnectionReusable() const;
+
void GetSSLInfo(SSLInfo* ssl_info);
void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info);