diff --git a/panda/src/downloader/downloader.cxx b/panda/src/downloader/downloader.cxx index 660248fe82..d3cd4ee8be 100644 --- a/panda/src/downloader/downloader.cxx +++ b/panda/src/downloader/downloader.cxx @@ -718,6 +718,13 @@ parse_http_response(const string &resp) { case 204: case 205: break; + case 302: + if (downloader_cat.is_debug()) + downloader_cat.debug() + << "Downloader::parse_http_response() - got a 302 redirect" + << endl; + return EU_http_redirect; + break; case 408: return EU_error_http_server_timeout; case 503: @@ -776,6 +783,7 @@ parse_header(DownloadStatus *status) { // The first line of the response should say whether // got an error or not + bool redirect = false; if (status->_first_line_complete == false) { status->_first_line_complete = true; int parse_ret = parse_http_response(component); @@ -785,12 +793,15 @@ parse_header(DownloadStatus *status) { << "Downloader::parse_header() - Header is valid: " << component << endl; status->_header_is_valid = true; + } else if (parse_ret == EU_http_redirect) { + redirect = true; + status->_header_is_valid = true; } else { return parse_ret; } } - // Look for content length + // Look for content length and location size_t cpos = component.find(":"); string tline = component.substr(0, cpos); if (status->_partial_content == true && tline == "Content-Length") { @@ -807,6 +818,13 @@ parse_header(DownloadStatus *status) { << status->_last_byte << "-" << status->_first_byte << ")" << endl; return EU_error_abort; } + } else if (redirect == true && tline == "Location") { + tline = component.substr(cpos + 2, string::npos); + if (downloader_cat.is_debug()) + downloader_cat.debug() + << "Downloader::parse_header() - file redirected to: " + << tline << endl; + return EU_error_abort; } // Two consecutive (CR LF)s indicates end of HTTP header diff --git a/panda/src/express/error_utils.h b/panda/src/express/error_utils.h index 85bb4b27da..d438561213 100644 --- a/panda/src/express/error_utils.h +++ b/panda/src/express/error_utils.h @@ -12,6 +12,7 @@ BEGIN_PUBLISH enum ErrorUtilCode { + EU_http_redirect = 7, EU_eof = 6, EU_network_no_data = 5,