Skip to content

Commit

Permalink
Fix an issue that FTP content length in download is not parsed correc…
Browse files Browse the repository at this point in the history
…tly.

Instead of directly parsing content length from http header. We should
use accessor function in URLRequest and ResourceResponseHead, which gets
the content length from different URLRequestJob backends that support
multiple protocols.

Bug: 771514
Change-Id: I60d8d13ab0f12b4e0f558d6611f0129e20435ea6
Reviewed-on: https://chromium-review.googlesource.com/710334
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Reviewed-by: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#508088}
  • Loading branch information
Xing Liu authored and Commit Bot committed Oct 11, 2017
1 parent 3db7455 commit dc435c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 7 additions & 0 deletions content/browser/download/download_request_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ bool DownloadRequestCore::OnResponseStarted(
const net::HttpResponseHeaders* headers = request()->response_headers();
HandleResponseHeaders(headers, create_info.get());

// If the content-length header is not present (or contains something other
// than numbers), the incoming content_length is -1 (unknown size).
// Set the content length to 0 to indicate unknown size to DownloadManager.
create_info->total_bytes = request()->GetExpectedContentSize() > 0
? request()->GetExpectedContentSize()
: 0;

// GURL::GetOrigin() doesn't support getting the inner origin of a blob URL.
// However, requesting a cross origin blob URL would have resulted in a
// network error, so we'll just ignore them here. Furthermore, we consider
Expand Down
1 change: 1 addition & 0 deletions content/browser/download/download_response_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ DownloadResponseHandler::CreateDownloadCreateInfo(
*head.headers, create_info->save_info.get(), fetch_error_body_)
: DOWNLOAD_INTERRUPT_REASON_NONE;

create_info->total_bytes = head.content_length > 0 ? head.content_length : 0;
create_info->result = result;
if (result == DOWNLOAD_INTERRUPT_REASON_NONE)
create_info->remote_address = head.socket_address.host();
Expand Down
5 changes: 0 additions & 5 deletions content/browser/download/download_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,6 @@ void HandleResponseHeaders(const net::HttpResponseHeaders* headers,
if (!headers)
return;

// Parse the "Content-Length" header. Adjust to 0 if no valid content_length
// presents.
int64_t content_length = headers->GetContentLength();
create_info->total_bytes = (content_length == -1) ? 0 : content_length;

if (headers->HasStrongValidators()) {
// If we don't have strong validators as per RFC 7232 section 2, then
// we neither store nor use them for range requests.
Expand Down

0 comments on commit dc435c7

Please sign in to comment.