Index: content/browser/download/download_resource_handler.cc |
diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc |
index 29f7e8e194fcca59bb94c18c8a81f493ca7e0588..fa4fb84a761a66a923bc7e080795e729500b7d74 100644 |
--- a/content/browser/download/download_resource_handler.cc |
+++ b/content/browser/download/download_resource_handler.cc |
@@ -172,6 +172,14 @@ bool DownloadResourceHandler::OnResponseStarted( |
info->last_modified = last_modified_hdr; |
if (headers->EnumerateHeader(NULL, "ETag", &etag)) |
info->etag = etag; |
+ |
+ int status = headers->response_code(); |
+ if (status == 200) { // Continue with download: |
+ // Downloading the full file, even if we asked for a range. |
+ // If there is a temporary file and |received_bytes == 0|, delete it. |
+ save_info_->offset = 0; |
+ save_info_->hash_state = ""; |
+ } |
} |
std::string content_type_header; |
@@ -322,19 +330,32 @@ bool DownloadResourceHandler::OnResponseCompleted( |
reason = DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; |
} |
- if (status.is_success()) { |
- if (response_code >= 400) { |
+ if (status.is_success() && |
+ (reason == DOWNLOAD_INTERRUPT_REASON_NONE) && |
+ request_->response_headers()) { |
+ // Handle server's response codes. |
+ if ((response_code >= 0) && ((response_code % 100) != 2)) { |
switch(response_code) { |
- case 404: // File Not Found. |
+ // Continue with download: |
+ case 200: // Downloading the full file, even if we asked for a |
+ // range. |
+ case 206: // Partial content. Leave alone. |
+ break; |
+ case 204: // No content. File not present. |
+ case 404: // File Not Found. |
reason = DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; |
break; |
+ case 412: // Precondition failed. Fails 'If-Unmodified-Since' or |
+ // 'If-Match'. |
+ reason = DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION; |
+ break; |
case 416: // Range Not Satisfiable. |
+ // Retry by downloading from the start automatically: |
+ // If we haven't received data when we get this error, we won't. |
reason = DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE; |
- break; |
- case 412: // Precondition Failed. |
reason = DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION; |
break; |
- default: |
+ default: // All other errors. |
reason = DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; |
break; |
} |