support servers that don't handle a Range request

This commit is contained in:
David Rose 2006-11-05 00:33:55 +00:00
parent 6ff2802afc
commit 1b3f098b39
3 changed files with 84 additions and 4 deletions

View File

@ -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

View File

@ -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());

View File

@ -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();