summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_network_transaction_unittest.cc58
-rw-r--r--net/http/http_stream_parser.cc4
2 files changed, 59 insertions, 3 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 9639457..4a71ab1 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -1,10 +1,13 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
#include <math.h> // ceil
+#include <vector>
#include "base/compiler_specific.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
#include "net/base/completion_callback.h"
#include "net/base/mock_host_resolver.h"
#include "net/base/request_priority.h"
@@ -3966,4 +3969,57 @@ TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) {
EXPECT_EQ("", out.response_data);
}
+TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) {
+ SessionDependencies session_deps;
+ scoped_ptr<HttpTransaction> trans(
+ new HttpNetworkTransaction(CreateSession(&session_deps)));
+
+ HttpRequestInfo request;
+ request.method = "POST";
+ request.url = GURL("http://www.google.com/upload");
+ request.upload_data = new UploadData;
+ request.load_flags = 0;
+
+ FilePath temp_file_path;
+ ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path));
+ const uint64 kFakeSize = 100000; // file is actually blank
+
+ std::vector<UploadData::Element> elements;
+ UploadData::Element element;
+ element.SetToFilePath(temp_file_path);
+ element.SetContentLength(kFakeSize);
+ elements.push_back(element);
+ request.upload_data->set_elements(elements);
+ EXPECT_EQ(kFakeSize, request.upload_data->GetContentLength());
+
+ MockRead data_reads[] = {
+ MockRead("HTTP/1.0 200 OK\r\n\r\n"),
+ MockRead("hello world"),
+ MockRead(false, OK),
+ };
+ StaticSocketDataProvider data(data_reads, NULL);
+ session_deps.socket_factory.AddSocketDataProvider(&data);
+
+ TestCompletionCallback callback;
+
+ int rv = trans->Start(&request, &callback, NULL);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ rv = callback.WaitForResult();
+ EXPECT_EQ(OK, rv);
+
+ const HttpResponseInfo* response = trans->GetResponseInfo();
+ EXPECT_TRUE(response != NULL);
+
+ EXPECT_TRUE(response->headers != NULL);
+ EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
+
+ std::string response_data;
+ rv = ReadTransaction(trans.get(), &response_data);
+ EXPECT_EQ(OK, rv);
+ EXPECT_EQ("hello world", response_data);
+
+ file_util::Delete(temp_file_path, false);
+}
+
} // namespace net
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index abbf112..9ec0ad6 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -210,7 +210,7 @@ int HttpStreamParser::DoSendBody(int result) {
if (result > 0)
request_body_->DidConsume(result);
- if (request_body_->position() < request_body_->size()) {
+ if (!request_body_->eof()) {
int buf_len = static_cast<int>(request_body_->buf_len());
result = connection_->socket()->Write(request_body_->buf(), buf_len,
&io_callback_);