Skip to content

Commit

Permalink
fixed: Some http servers provide different content when the range req…
Browse files Browse the repository at this point in the history
…uest header is not set causing seeking to fail. To fix this use CURL_OPT_RANGE method instead of CURLOPT_RESUME_FROM_LARGE
  • Loading branch information
arnova authored and davilla committed Mar 11, 2013
1 parent d5b2bfe commit 169d21d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions xbmc/filesystem/CurlFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,22 @@ bool CCurlFile::CReadState::Seek(int64_t pos)
return false;
}

void CCurlFile::CReadState::SetResume(void)
{
/*
* Use RANGE method for resuming. We used to use RESUME_FROM_LARGE for this but some http servers
* require us to always send the range request header. If we don't the server may provide different
* content causing seeking to fail. Note that internally Curl will automatically handle this for FTP
* so we don't need to worry about that here.
*/
char str[21];
sprintf(str, "%"PRId64"-", m_filePos);
g_curlInterface.easy_setopt(m_easyHandle, CURLOPT_RANGE, str);
}

long CCurlFile::CReadState::Connect(unsigned int size)
{
g_curlInterface.easy_setopt(m_easyHandle, CURLOPT_RESUME_FROM_LARGE, m_filePos);
SetResume();
g_curlInterface.multi_add_handle(m_multiHandle, m_easyHandle);

m_bufferSize = size;
Expand Down Expand Up @@ -1308,7 +1321,7 @@ bool CCurlFile::CReadState::FillBuffer(unsigned int want)
CLog::Log(LOGWARNING, "%s: Reconnect, (re)try %i", __FUNCTION__, retry);

// Connect + seek to current position (again)
g_curlInterface.easy_setopt(m_easyHandle, CURLOPT_RESUME_FROM_LARGE, m_filePos);
SetResume();
g_curlInterface.multi_add_handle(m_multiHandle, m_easyHandle);

// Return to the beginning of the loop:
Expand Down
1 change: 1 addition & 0 deletions xbmc/filesystem/CurlFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace XFILE
bool ReadString(char *szLine, int iLineLength);
bool FillBuffer(unsigned int want);

void SetResume(void);
long Connect(unsigned int size);
void Disconnect();
};
Expand Down

2 comments on commit 169d21d

@arnova
Copy link
Member

@arnova arnova commented on 169d21d Mar 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davilla: Huh? Did this get merged to 12.1? I don't recall putting this on the list....

EDIT: The reason I ask is that this should have never been merged for 12.1

@davilla
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was placed on the backport list by ulion in post #123, 7 days before release. There was no complaints when this was done and the commit was included into 12.1 release. Next time, please make sure you monitor the backport list.

Please sign in to comment.