diff --git a/panda/src/downloader/httpChannel.I b/panda/src/downloader/httpChannel.I index aeaecb458e..ce26171a0c 100644 --- a/panda/src/downloader/httpChannel.I +++ b/panda/src/downloader/httpChannel.I @@ -518,6 +518,70 @@ is_file_size_known() const { return _got_file_size; } +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::get_first_byte_requested +// Access: Published +// Description: Returns the first byte of the file requested by the +// request. This will normally be 0 to indicate that +// the file is being requested from the beginning, but +// if the file was requested via a get_subdocument() +// call, this will contain the first_byte parameter from +// that call. +//////////////////////////////////////////////////////////////////// +INLINE size_t HTTPChannel:: +get_first_byte_requested() const { + return _first_byte_requested; +} + +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::get_last_byte_requested +// Access: Published +// Description: Returns the last byte of the file requested by the +// request. This will normally be 0 to indicate that +// the file is being requested to its last byte, but if +// the file was requested via a get_subdocument() call, +// this will contain the last_byte parameter from that +// call. +//////////////////////////////////////////////////////////////////// +INLINE size_t HTTPChannel:: +get_last_byte_requested() const { + return _last_byte_requested; +} + +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::get_first_byte_delivered +// Access: Published +// Description: Returns the first byte of the file (that will be) +// delivered by the server in response to the current +// request. Normally, this is the same as +// get_first_byte_requested(), but some servers will +// ignore a subdocument request and always return the +// whole file, in which case this value will be 0, +// regardless of what was requested to +// get_subdocument(). +//////////////////////////////////////////////////////////////////// +INLINE size_t HTTPChannel:: +get_first_byte_delivered() const { + return _first_byte_delivered; +} + +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::get_last_byte_delivered +// Access: Published +// Description: Returns the last byte of the file (that will be) +// delivered by the server in response to the current +// request. Normally, this is the same as +// get_last_byte_requested(), but some servers will +// ignore a subdocument request and always return the +// whole file, in which case this value will be 0, +// regardless of what was requested to +// get_subdocument(). +//////////////////////////////////////////////////////////////////// +INLINE size_t HTTPChannel:: +get_last_byte_delivered() const { + return _last_byte_delivered; +} + //////////////////////////////////////////////////////////////////// // Function: HTTPChannel::reset // Access: Published diff --git a/panda/src/downloader/httpChannel.cxx b/panda/src/downloader/httpChannel.cxx index e6932fcd6d..deb9e0c9e0 100644 --- a/panda/src/downloader/httpChannel.cxx +++ b/panda/src/downloader/httpChannel.cxx @@ -621,7 +621,7 @@ download_to_file(const Filename &filename, bool subdocument_resumes) { _download_to_file.close(); _download_to_file.clear(); - _subdocument_resumes = (subdocument_resumes && _first_byte_requested != 0); + _subdocument_resumes = (subdocument_resumes && _first_byte_delivered != 0); if (!_download_to_filename.open_write(_download_to_file, !_subdocument_resumes)) { downloader_cat.info() @@ -630,7 +630,7 @@ download_to_file(const Filename &filename, bool subdocument_resumes) { } _download_dest = DD_file; - if (!reset_download_position(_first_byte_requested)) { + if (!reset_download_position(_first_byte_delivered)) { reset_download_to(); return false; } @@ -684,9 +684,9 @@ download_to_ram(Ramfile *ramfile, bool subdocument_resumes) { ramfile->_pos = 0; _download_to_ramfile = ramfile; _download_dest = DD_ram; - _subdocument_resumes = (subdocument_resumes && _first_byte_requested != 0); + _subdocument_resumes = (subdocument_resumes && _first_byte_delivered != 0); - if (!reset_download_position(_first_byte_requested)) { + if (!reset_download_position(_first_byte_delivered)) { reset_download_to(); return false; } @@ -1685,6 +1685,17 @@ run_reading_header() { _first_byte_delivered = 0; _last_byte_delivered = 0; } + if (downloader_cat.is_debug()) { + if (_first_byte_requested != 0 || _last_byte_requested != 0 || + _first_byte_delivered != 0 || _last_byte_delivered != 0) { + downloader_cat.debug() + << "Requested byte range " << _first_byte_requested + << " to " << _last_byte_delivered + << "; server delivers range " << _first_byte_delivered + << " to " << _last_byte_delivered + << "\n"; + } + } // Set the _document_spec to reflect what we just retrieved. _document_spec = DocumentSpec(_request.get_url()); diff --git a/panda/src/downloader/httpChannel.h b/panda/src/downloader/httpChannel.h index c780e0733d..8116e4aa1a 100644 --- a/panda/src/downloader/httpChannel.h +++ b/panda/src/downloader/httpChannel.h @@ -150,6 +150,11 @@ PUBLISHED: virtual off_t get_file_size() const; INLINE bool is_file_size_known() const; + INLINE size_t get_first_byte_requested() const; + INLINE size_t get_last_byte_requested() const; + INLINE size_t get_first_byte_delivered() const; + INLINE size_t get_last_byte_delivered() const; + void write_headers(ostream &out) const; INLINE void reset();