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 1de77f79d67791618d389d627e7eaf9f2cf8a916..d9a9ab250710eee5f6f081b33dd91fe7aa43adf9 100644 |
--- a/content/browser/download/download_resource_handler.cc |
+++ b/content/browser/download/download_resource_handler.cc |
@@ -181,6 +181,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. |
+ info->received_bytes = 0; |
+ info->save_info.hash_state = ""; |
+ } |
} |
std::string content_type_header; |
@@ -334,19 +342,31 @@ bool DownloadResourceHandler::OnResponseCompleted( |
reason = content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; |
} |
- if (status.is_success()) { |
- if (response_code >= 400) { |
- switch(response_code) { |
- case 404: // File Not Found. |
- reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; |
+ if (status.is_success() && |
+ (reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) && |
+ request_->response_headers()) { |
+ // Handle server's response codes. |
+ if ((response_code >= 0) && ((response_code % 100) != 2)) { |
+ switch(response_code) { |
+ // 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 = content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; |
+ break; |
+ case 412: // Precondition failed. Fails 'If-Unmodified-Since' or |
+ // 'If-Match'. |
+ reason = content::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 = content::DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE; |
break; |
- case 412: // Precondition Failed. |
- reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION; |
- break; |
- default: |
+ default: // All other errors. |
reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; |
break; |
} |