Skip to content

Commit

Permalink
MythSingleDownload: add option to return final (post-redirect) URL
Browse files Browse the repository at this point in the history
Refs #13488
Signed-off-by: Paul Harrison <pharrison@mythtv.org>
(cherry picked from commit 753fdd8)
  • Loading branch information
ijc authored and Paul Harrison committed Oct 5, 2019
1 parent 783e0df commit 13976ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions mythtv/libs/libmythbase/mythsingledownload.cpp
Expand Up @@ -12,7 +12,7 @@
#define LOC QString("MythSingleDownload: ")

bool MythSingleDownload::DownloadURL(const QUrl &url, QByteArray *buffer,
uint timeout, uint redirs, qint64 maxsize)
uint timeout, uint redirs, qint64 maxsize, QString *final_url)
{
m_lock.lock();

Expand Down Expand Up @@ -73,14 +73,16 @@ bool MythSingleDownload::DownloadURL(const QUrl &url, QByteArray *buffer,
LOG(VB_GENERAL, LOG_INFO, QString("%1 -> %2").arg(url.toString()).arg(redir));
m_replylock.unlock();
m_lock.unlock();
return DownloadURL(redir, buffer, timeout, redirs + 1);
return DownloadURL(redir, buffer, timeout, redirs + 1, maxsize, final_url);
}

LOG(VB_GENERAL, LOG_ERR, QString("%1: too many redirects").arg(url.toString()));
ret = false;
}
else if (m_errorcode == QNetworkReply::NoError)
{
if (final_url != nullptr)
*final_url = url.toString();
*m_buffer += m_reply->readAll();
m_errorstring.clear();
ret = true;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythsingledownload.h
Expand Up @@ -29,7 +29,7 @@ class MBASE_PUBLIC MythSingleDownload : public QObject
~MythSingleDownload(void) = default;

bool DownloadURL(const QUrl &url, QByteArray *buffer, uint timeout = 30000,
uint redirs = 0, qint64 maxsize = 0);
uint redirs = 0, qint64 maxsize = 0, QString *final_url = nullptr);
void Cancel(void);
QString ErrorString(void) const { return m_errorstring; }
QNetworkReply::NetworkError ErrorCode(void) const { return m_errorcode; }
Expand Down

0 comments on commit 13976ea

Please sign in to comment.