mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Media downloader: Fix case with redirect response
This commit is contained in:
parent
fcb63af661
commit
afd3dc2014
|
@ -3,13 +3,22 @@
|
||||||
|
|
||||||
namespace Dictionary {
|
namespace Dictionary {
|
||||||
|
|
||||||
|
#define MAX_REDIRECTS 10
|
||||||
|
|
||||||
WebMultimediaDownload::WebMultimediaDownload( QUrl const & url,
|
WebMultimediaDownload::WebMultimediaDownload( QUrl const & url,
|
||||||
QNetworkAccessManager & mgr )
|
QNetworkAccessManager & _mgr ) :
|
||||||
|
mgr( _mgr ),
|
||||||
|
redirectCount( 0 )
|
||||||
{
|
{
|
||||||
connect( &mgr, SIGNAL(finished(QNetworkReply*)),
|
connect( &mgr, SIGNAL(finished(QNetworkReply*)),
|
||||||
this, SLOT(replyFinished(QNetworkReply*)), Qt::QueuedConnection );
|
this, SLOT(replyFinished(QNetworkReply*)), Qt::QueuedConnection );
|
||||||
|
|
||||||
reply = mgr.get( QNetworkRequest( url ) );
|
reply = mgr.get( QNetworkRequest( url ) );
|
||||||
|
|
||||||
|
#ifndef QT_NO_OPENSSL
|
||||||
|
connect( reply, SIGNAL( sslErrors( QList< QSslError > ) ),
|
||||||
|
reply, SLOT( ignoreSslErrors() ) );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebMultimediaDownload::cancel()
|
void WebMultimediaDownload::cancel()
|
||||||
|
@ -26,6 +35,31 @@ void WebMultimediaDownload::replyFinished( QNetworkReply * r )
|
||||||
|
|
||||||
if ( r->error() == QNetworkReply::NoError )
|
if ( r->error() == QNetworkReply::NoError )
|
||||||
{
|
{
|
||||||
|
// Check for redirect reply
|
||||||
|
|
||||||
|
QVariant possibleRedirectUrl = reply->attribute( QNetworkRequest::RedirectionTargetAttribute );
|
||||||
|
QUrl redirectUrl = possibleRedirectUrl.toUrl();
|
||||||
|
if( !redirectUrl.isEmpty() )
|
||||||
|
{
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if( ++redirectCount > MAX_REDIRECTS )
|
||||||
|
{
|
||||||
|
setErrorString( "Too many redirects detected" );
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reply = mgr.get( QNetworkRequest( redirectUrl ) );
|
||||||
|
#ifndef QT_NO_OPENSSL
|
||||||
|
connect( reply, SIGNAL( sslErrors( QList< QSslError > ) ),
|
||||||
|
reply, SLOT( ignoreSslErrors() ) );
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle reply data
|
||||||
|
|
||||||
QByteArray all = r->readAll();
|
QByteArray all = r->readAll();
|
||||||
|
|
||||||
Mutex::Lock _( dataMutex );
|
Mutex::Lock _( dataMutex );
|
||||||
|
|
|
@ -13,6 +13,8 @@ class WebMultimediaDownload: public DataRequest
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
QNetworkReply * reply;
|
QNetworkReply * reply;
|
||||||
|
QNetworkAccessManager & mgr;
|
||||||
|
int redirectCount;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue