@@ -323,10 +323,11 @@ def load(self):
323
323
settings .endGroup ()
324
324
325
325
# ----------------------------------------- #
326
- def requestFetching (self , key ):
326
+ def requestFetching (self , key , url = None , redirectionCounter = 0 ):
327
327
""" start fetching the repository given by key """
328
328
self .mRepositories [key ]["state" ] = 1
329
- url = QUrl (self .mRepositories [key ]["url" ] + self .urlParams ())
329
+ if not url :
330
+ url = QUrl (self .mRepositories [key ]["url" ] + self .urlParams ())
330
331
# v=str(Qgis.QGIS_VERSION_INT)
331
332
# url.addQueryItem('qgis', '.'.join([str(int(s)) for s in [v[0], v[1:3]]]) ) # don't include the bugfix version!
332
333
@@ -345,6 +346,7 @@ def requestFetching(self, key):
345
346
self .mRepositories [key ]["QRequest" ].setAttribute (QNetworkRequest .User , key )
346
347
self .mRepositories [key ]["xmlData" ] = QgsNetworkAccessManager .instance ().get (self .mRepositories [key ]["QRequest" ])
347
348
self .mRepositories [key ]["xmlData" ].setProperty ('reposName' , key )
349
+ self .mRepositories [key ]["xmlData" ].setProperty ('redirectionCounter' , redirectionCounter )
348
350
self .mRepositories [key ]["xmlData" ].downloadProgress .connect (self .mRepositories [key ]["Relay" ].dataReadProgress )
349
351
self .mRepositories [key ]["xmlData" ].finished .connect (self .xmlDownloaded )
350
352
@@ -373,6 +375,19 @@ def xmlDownloaded(self):
373
375
self .mRepositories [reposName ]["error" ] = reply .errorString ()
374
376
if reply .error () == QNetworkReply .OperationCanceledError :
375
377
self .mRepositories [reposName ]["error" ] += "\n \n " + QCoreApplication .translate ("QgsPluginInstaller" , "If you haven't canceled the download manually, it was most likely caused by a timeout. In this case consider increasing the connection timeout value in QGIS options window." )
378
+ elif reply .attribute (QNetworkRequest .HttpStatusCodeAttribute ) == 301 :
379
+ redirectionUrl = reply .attribute (QNetworkRequest .RedirectionTargetAttribute )
380
+ if redirectionUrl .isRelative ():
381
+ redirectionUrl = reply .url ().resolved (redirectionUrl )
382
+ redirectionCounter = reply .property ('redirectionCounter' ) + 1
383
+ if redirectionCounter > 4 :
384
+ self .mRepositories [reposName ]["state" ] = 3
385
+ self .mRepositories [reposName ]["error" ] = QCoreApplication .translate ("QgsPluginInstaller" , "Too many redirections" )
386
+ else :
387
+ # Fire a new request and exit immediately in order to quietly destroy the old one
388
+ self .requestFetching (reposName , redirectionUrl , redirectionCounter )
389
+ reply .deleteLater ()
390
+ return
376
391
else :
377
392
reposXML = QDomDocument ()
378
393
content = reply .readAll ()
0 commit comments