From 8f1999f63dbfd31f79eb99e8ee055918556cc544 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 12 May 2010 21:58:01 +0000 Subject: [PATCH] fix some edge conditions with non-blocking download_to_file --- panda/src/downloader/httpChannel.cxx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/panda/src/downloader/httpChannel.cxx b/panda/src/downloader/httpChannel.cxx index a2b0708715..7f81a7faeb 100644 --- a/panda/src/downloader/httpChannel.cxx +++ b/panda/src/downloader/httpChannel.cxx @@ -640,7 +640,7 @@ download_to_file(const Filename &filename, bool subdocument_resumes) { _download_dest = DD_file; - if (_wanted_nonblocking) { + if (_wanted_nonblocking && _state != S_read_header) { // In nonblocking mode, we can't start the download yet; that will // be done later as run() is called. return true; @@ -697,7 +697,7 @@ download_to_ram(Ramfile *ramfile, bool subdocument_resumes) { _download_dest = DD_ram; _subdocument_resumes = (subdocument_resumes && _first_byte_delivered != 0); - if (_wanted_nonblocking) { + if (_wanted_nonblocking && _state != S_read_header) { // In nonblocking mode, we can't start the download yet; that will // be done later as run() is called. return true; @@ -757,7 +757,7 @@ download_to_stream(ostream *strm, bool subdocument_resumes) { _download_dest = DD_stream; - if (_wanted_nonblocking) { + if (_wanted_nonblocking && _state != S_read_header) { // In nonblocking mode, we can't start the download yet; that will // be done later as run() is called. return true; @@ -1881,6 +1881,11 @@ run_reading_header() { // In case we've got a download in effect, now we know what the // first byte of the subdocument request will be, so we can open the // file and position it. + if (_server_response_has_no_body) { + // Never mind on the download. + reset_download_to(); + } + if (!open_download_file()) { return false; } @@ -1963,8 +1968,11 @@ run_reading_header() { } } - if ((get_status_code() / 100) == 3 && get_status_code() != 305 && - !get_redirect().empty()) { + if ((get_status_code() == 300 || + get_status_code() == 301 || + get_status_code() == 302 || + get_status_code() == 303 || + get_status_code() == 307) && !get_redirect().empty()) { // Redirect. Should we handle it automatically? // According to the letter of RFC 2616, 301 and 302 responses to