File tree Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,14 @@ Fetches content from a remote URL and handles redirects. The finished()
40
40
signal will be emitted when content has been fetched.
41
41
42
42
:param url: URL to fetch
43
+ %End
44
+
45
+ void fetchContent( const QNetworkRequest &request );
46
+ %Docstring
47
+ Fetches content using a network ``request`` and handles redirects. The finished()
48
+ signal will be emitted when content has been fetched.
49
+
50
+ .. versionadded:: 3.2
43
51
%End
44
52
45
53
QNetworkReply *reply();
Original file line number Diff line number Diff line change @@ -38,10 +38,12 @@ QgsNetworkContentFetcher::~QgsNetworkContentFetcher()
38
38
39
39
void QgsNetworkContentFetcher::fetchContent ( const QUrl &url )
40
40
{
41
- mContentLoaded = false ;
41
+ fetchContent ( QNetworkRequest ( url ) );
42
+ }
42
43
43
- // get contents
44
- QNetworkRequest request ( url );
44
+ void QgsNetworkContentFetcher::fetchContent ( const QNetworkRequest &request )
45
+ {
46
+ mContentLoaded = false ;
45
47
46
48
if ( mReply )
47
49
{
Original file line number Diff line number Diff line change @@ -54,6 +54,14 @@ class CORE_EXPORT QgsNetworkContentFetcher : public QObject
54
54
*/
55
55
void fetchContent ( const QUrl &url );
56
56
57
+ /* *
58
+ * Fetches content using a network \a request and handles redirects. The finished()
59
+ * signal will be emitted when content has been fetched.
60
+ *
61
+ * \since QGIS 3.2
62
+ */
63
+ void fetchContent ( const QNetworkRequest &request );
64
+
57
65
/* *
58
66
* Returns a reference to the network reply
59
67
* \returns QNetworkReply for fetched URL content
Original file line number Diff line number Diff line change 22
22
from qgis .core import QgsNetworkContentFetcher
23
23
from utilities import unitTestDataPath
24
24
from qgis .PyQt .QtCore import QUrl
25
- from qgis .PyQt .QtNetwork import QNetworkReply
25
+ from qgis .PyQt .QtNetwork import QNetworkReply , QNetworkRequest
26
26
import socketserver
27
27
import threading
28
28
import http .server
@@ -90,6 +90,21 @@ def testFetchUrlContent(self):
90
90
html = fetcher .contentAsString ()
91
91
assert 'QGIS' in html
92
92
93
+ def testFetchRequestContent (self ):
94
+ fetcher = QgsNetworkContentFetcher ()
95
+ self .loaded = False
96
+ request = QNetworkRequest (QUrl ('http://localhost:' + str (TestQgsNetworkContentFetcher .port ) + '/qgis_local_server/index.html' ))
97
+ fetcher .fetchContent (request )
98
+ fetcher .finished .connect (self .contentLoaded )
99
+ while not self .loaded :
100
+ app .processEvents ()
101
+
102
+ r = fetcher .reply ()
103
+ assert r .error () == QNetworkReply .NoError , r .error ()
104
+
105
+ html = fetcher .contentAsString ()
106
+ assert 'QGIS' in html
107
+
93
108
def testDoubleFetch (self ):
94
109
fetcher = QgsNetworkContentFetcher ()
95
110
self .loaded = False
You can’t perform that action at this time.
0 commit comments