diff options
author | twifkak <twifkak@chromium.org> | 2015-08-13 20:31:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-14 03:32:13 +0000 |
commit | a87733536abbce7255245315ce529e9dfba73a07 (patch) | |
tree | 6ccbb8d0dc113eef16903ad13141d9778a7673b1 /net | |
parent | d482a34648c7054aa4b7b714468594591b447e3d (diff) | |
download | chromium_src-a87733536abbce7255245315ce529e9dfba73a07.zip chromium_src-a87733536abbce7255245315ce529e9dfba73a07.tar.gz chromium_src-a87733536abbce7255245315ce529e9dfba73a07.tar.bz2 |
Fix response bytes getters in URLFetcher.
Change URLFetcherCore to read the values for
GetReceivedResponseContentLength() and GetTotalReceivedBytes() after the
request has finished processing, rather than immediately after the
response started. Add tests to verify this.
BUG=
Review URL: https://codereview.chromium.org/1285403002
Cr-Commit-Position: refs/heads/master@{#343337}
Diffstat (limited to 'net')
-rw-r--r-- | net/url_request/url_fetcher.h | 3 | ||||
-rw-r--r-- | net/url_request/url_fetcher_core.cc | 6 | ||||
-rw-r--r-- | net/url_request/url_fetcher_impl_unittest.cc | 13 | ||||
-rw-r--r-- | net/url_request/url_request.h | 7 |
4 files changed, 24 insertions, 5 deletions
diff --git a/net/url_request/url_fetcher.h b/net/url_request/url_fetcher.h index 49196af..f13b403 100644 --- a/net/url_request/url_fetcher.h +++ b/net/url_request/url_fetcher.h @@ -292,7 +292,8 @@ class NET_EXPORT URLFetcher { virtual int64_t GetReceivedResponseContentLength() const = 0; // The number of bytes received over the network during the processing of this - // request. + // request. This includes redirect headers, but not redirect bodies. It also + // excludes SSL and proxy handshakes. virtual int64_t GetTotalReceivedBytes() const = 0; // Start the request. After this is called, you may not change any other diff --git a/net/url_request/url_fetcher_core.cc b/net/url_request/url_fetcher_core.cc index de55ef7..e07dcdf 100644 --- a/net/url_request/url_fetcher_core.cc +++ b/net/url_request/url_fetcher_core.cc @@ -424,9 +424,6 @@ void URLFetcherCore::OnResponseStarted(URLRequest* request) { socket_address_ = request_->GetSocketAddress(); was_fetched_via_proxy_ = request_->was_fetched_via_proxy(); was_cached_ = request_->was_cached(); - received_response_content_length_ = - request_->received_response_content_length(); - total_received_bytes_ += request_->GetTotalReceivedBytes(); total_response_bytes_ = request_->GetExpectedContentSize(); } @@ -480,6 +477,9 @@ void URLFetcherCore::OnReadCompleted(URLRequest* request, // See comments re: HEAD requests in ReadResponse(). if (!status.is_io_pending() || request_type_ == URLFetcher::HEAD) { status_ = status; + received_response_content_length_ = + request_->received_response_content_length(); + total_received_bytes_ += request_->GetTotalReceivedBytes(); ReleaseRequest(); // No more data to write. diff --git a/net/url_request/url_fetcher_impl_unittest.cc b/net/url_request/url_fetcher_impl_unittest.cc index ef7c307..5432391 100644 --- a/net/url_request/url_fetcher_impl_unittest.cc +++ b/net/url_request/url_fetcher_impl_unittest.cc @@ -4,6 +4,9 @@ #include "net/url_request/url_fetcher_impl.h" +#include <stdint.h> +#include <string.h> + #include <algorithm> #include <string> @@ -15,6 +18,7 @@ #include "base/path_service.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" +#include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/synchronization/waitable_event.h" #include "base/thread_task_runner_handle.h" @@ -471,6 +475,15 @@ TEST_F(URLFetcherTest, SameThreadTest) { std::string data; ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); EXPECT_EQ(kDefaultResponseBody, data); + + EXPECT_EQ(static_cast<int64_t>(strlen(kDefaultResponseBody)), + delegate.fetcher()->GetReceivedResponseContentLength()); + std::string parsed_headers; + base::ReplaceChars(delegate.fetcher()->GetResponseHeaders()->raw_headers(), + std::string("\0", 1), "\n\r", &parsed_headers); + EXPECT_EQ(static_cast<int64_t>(parsed_headers.size() + + strlen(kDefaultResponseBody)), + delegate.fetcher()->GetTotalReceivedBytes()); } // Create a separate thread that will create the URLFetcher. A separate thread diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 4176689..56f326f 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -356,7 +356,8 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), bool GetFullRequestHeaders(HttpRequestHeaders* headers) const; // Gets the total amount of data received from network after SSL decoding and - // proxy handling. + // proxy handling. Pertains only to the last URLRequestJob issued by this + // URLRequest -- i.e. the last redirect. int64 GetTotalReceivedBytes() const; // Returns the current load state for the request. The returned value's @@ -599,6 +600,10 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), void set_received_response_content_length(int64 received_content_length) { received_response_content_length_ = received_content_length; } + + // Available only for http/https/ws/wss URLs (those handled by + // URLRequestHttpJob), and only after the response has finished. Pertains to + // the last URLRequestHttpJob that this URLRequest issued. int64 received_response_content_length() const { return received_response_content_length_; } |