QGIS API Documentation 4.5.0-Master (3b5d115045b)
Loading...
Searching...
No Matches
qgsblockingnetworkrequest.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsblockingnetworkrequest.cpp
3 -----------------------------
4 begin : November 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgsapplication.h"
19#include "qgsauthmanager.h"
20#include "qgsfeedback.h"
21#include "qgslogger.h"
22#include "qgsmessagelog.h"
24#include "qgsvariantutils.h"
25
26#include <QAuthenticator>
27#include <QBuffer>
28#include <QMutex>
29#include <QNetworkCacheMetaData>
30#include <QNetworkReply>
31#include <QNetworkRequest>
32#include <QString>
33#include <QUrl>
34#include <QWaitCondition>
35
36#include "moc_qgsblockingnetworkrequest.cpp"
37
38using namespace Qt::StringLiterals;
39
41 : mFlags( flags )
42{
43 connect( QgsNetworkAccessManager::instance(), qOverload< QNetworkReply * >( &QgsNetworkAccessManager::requestTimedOut ), this, &QgsBlockingNetworkRequest::requestTimedOut );
44}
45
50
51void QgsBlockingNetworkRequest::requestTimedOut( QNetworkReply *reply )
52{
53 if ( reply == mReply )
54 mTimedout = true;
55}
56
58{
59 return mAuthCfg;
60}
61
63{
64 mAuthCfg = authCfg;
65}
66
67QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::get( QNetworkRequest &request, bool forceRefresh, QgsFeedback *feedback, RequestFlags requestFlags )
68{
69 return doRequest( Qgis::HttpMethod::Get, request, forceRefresh, feedback, requestFlags );
70}
71
72QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::post( QNetworkRequest &request, const QByteArray &data, bool forceRefresh, QgsFeedback *feedback )
73{
74 QByteArray ldata( data );
75 QBuffer buffer( &ldata );
76 buffer.open( QIODevice::ReadOnly );
77 return post( request, &buffer, forceRefresh, feedback );
78}
79
80QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::post( QNetworkRequest &request, QIODevice *data, bool forceRefresh, QgsFeedback *feedback )
81{
82 mPayloadDataVariant = data;
83 return doRequest( Qgis::HttpMethod::Post, request, forceRefresh, feedback );
84}
85
86QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::post( QNetworkRequest &request, QHttpMultiPart *data, bool forceRefresh, QgsFeedback *feedback )
87{
88 mPayloadDataVariant = data;
89 return doRequest( Qgis::HttpMethod::Post, request, forceRefresh, feedback );
90}
91
92QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::head( QNetworkRequest &request, bool forceRefresh, QgsFeedback *feedback )
93{
94 return doRequest( Qgis::HttpMethod::Head, request, forceRefresh, feedback );
95}
96
97QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::put( QNetworkRequest &request, const QByteArray &data, QgsFeedback *feedback )
98{
99 QByteArray ldata( data );
100 QBuffer buffer( &ldata );
101 buffer.open( QIODevice::ReadOnly );
102 return put( request, &buffer, feedback );
103}
104
105QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::put( QNetworkRequest &request, QIODevice *data, QgsFeedback *feedback )
106{
107 mPayloadDataVariant = data;
108 return doRequest( Qgis::HttpMethod::Put, request, true, feedback );
109}
110
111QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::patch( QNetworkRequest &request, const QByteArray &data, QgsFeedback *feedback )
112{
113 QByteArray ldata( data );
114 QBuffer buffer( &ldata );
115 buffer.open( QIODevice::ReadOnly );
116 return patch( request, &buffer, feedback );
117}
118
119QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::patch( QNetworkRequest &request, QIODevice *data, QgsFeedback *feedback )
120{
121 mPayloadDataVariant = data;
122 return doRequest( Qgis::HttpMethod::Patch, request, true, feedback );
123}
124
125
127{
128 return doRequest( Qgis::HttpMethod::Delete, request, true, feedback );
129}
130
131void QgsBlockingNetworkRequest::sendRequestToNetworkAccessManager( const QNetworkRequest &request )
132{
133 switch ( mMethod )
134 {
136 mReply = QgsNetworkAccessManager::instance()->get( request );
137 break;
138
140 if ( std::holds_alternative<QHttpMultiPart *>( mPayloadDataVariant ) )
141 {
142 mReply = QgsNetworkAccessManager::instance()->post( request, std::get<QHttpMultiPart *>( mPayloadDataVariant ) );
143 }
144 else if ( std::holds_alternative<QIODevice *>( mPayloadDataVariant ) )
145 {
146 mReply = QgsNetworkAccessManager::instance()->post( request, std::get<QIODevice *>( mPayloadDataVariant ) );
147 }
148 else
149 {
150 // should not happen, but might if someone extends the variant type without updating this code
151 QgsDebugError( QString( "Not implemented std::variant type" ) );
152 }
153 break;
154
156 mReply = QgsNetworkAccessManager::instance()->head( request );
157 break;
158
160 mReply = QgsNetworkAccessManager::instance()->put( request, std::get<QIODevice *>( mPayloadDataVariant ) );
161 break;
162
164 mReply = QgsNetworkAccessManager::instance()->deleteResource( request );
165 break;
166
168 mReply = QgsNetworkAccessManager::instance()->sendCustomRequest( request, "PATCH", std::get<QIODevice *>( mPayloadDataVariant ) );
169 break;
170 };
171}
172
173QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::doRequest( Qgis::HttpMethod method, QNetworkRequest &request, bool forceRefresh, QgsFeedback *feedback, RequestFlags requestFlags )
174{
175 mMethod = method;
176 mFeedback = feedback;
177
178 abort(); // cancel previous
179 mIsAborted = false;
180 mTimedout = false;
181 mGotNonEmptyResponse = false;
182 mRequestFlags = requestFlags;
183
184 mErrorMessage.clear();
185 mErrorCode = NoError;
186 mForceRefresh = forceRefresh;
187 mReplyContent.clear();
188
189 if ( !mAuthCfg.isEmpty() && !QgsApplication::authManager()->updateNetworkRequest( request, mAuthCfg ) )
190 {
191 mErrorCode = NetworkError;
192 mErrorMessage = errorMessageFailedAuth();
193 if ( !mFlags.testFlag( Qgis::NetworkRequestFlag::DisableMessageLogging ) )
194 {
195 QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
196 }
197 return NetworkError;
198 }
199
200 QgsDebugMsgLevel( u"Calling: %1"_s.arg( request.url().toString() ), 2 );
201
202 request.setAttribute( QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::ManualRedirectPolicy );
203 request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, forceRefresh ? QNetworkRequest::AlwaysNetwork : QNetworkRequest::PreferCache );
204 request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
205
206 QWaitCondition authRequestBufferNotEmpty;
207 QMutex waitConditionMutex;
208
209 bool threadFinished = false;
210 bool success = false;
211
212 const bool requestMadeFromMainThread = QThread::currentThread() == QApplication::instance()->thread();
213
214 if ( mFeedback )
215 connect( mFeedback, &QgsFeedback::canceled, this, &QgsBlockingNetworkRequest::abort );
216
217 const std::function<void()> downloaderFunction = [this, request, &waitConditionMutex, &authRequestBufferNotEmpty, &threadFinished, &success, requestMadeFromMainThread]() {
218 // this function will always be run in worker threads -- either the blocking call is being made in a worker thread,
219 // or the blocking call has been made from the main thread and we've fired up a new thread for this function
220 Q_ASSERT( QThread::currentThread() != QgsApplication::instance()->thread() );
221
222 QgsNetworkAccessManager::instance( Qt::DirectConnection );
223
224 success = true;
225
226 sendRequestToNetworkAccessManager( request );
227
228 if ( mFeedback )
229 connect( mFeedback, &QgsFeedback::canceled, mReply, &QNetworkReply::abort );
230
231 if ( !mAuthCfg.isEmpty() && !QgsApplication::authManager()->updateNetworkReply( mReply, mAuthCfg ) )
232 {
233 mErrorCode = NetworkError;
234 mErrorMessage = errorMessageFailedAuth();
235 if ( !mFlags.testFlag( Qgis::NetworkRequestFlag::DisableMessageLogging ) )
236 {
237 QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
238 }
239 if ( requestMadeFromMainThread )
240 authRequestBufferNotEmpty.wakeAll();
241 success = false;
242 }
243 else
244 {
245 // We are able to use direct connection here, because we
246 // * either run on the thread mReply lives in, so DirectConnection is standard and safe anyway
247 // * or the owner thread of mReply is currently not doing anything because it's blocked in future.waitForFinished() (if it is the main thread)
248 connect( mReply, &QNetworkReply::finished, this, &QgsBlockingNetworkRequest::replyFinished, Qt::DirectConnection );
249 connect( mReply, &QNetworkReply::downloadProgress, this, &QgsBlockingNetworkRequest::replyProgress, Qt::DirectConnection );
250 connect( mReply, &QNetworkReply::uploadProgress, this, &QgsBlockingNetworkRequest::replyProgress, Qt::DirectConnection );
251
252 if ( request.hasRawHeader( "Range" ) )
253 connect( mReply, &QNetworkReply::metaDataChanged, this, &QgsBlockingNetworkRequest::abortIfNotPartialContentReturned, Qt::DirectConnection );
254
255 auto resumeMainThread = [&waitConditionMutex, &authRequestBufferNotEmpty]() {
256 // when this method is called we have "produced" a single authentication request -- so the buffer is now full
257 // and it's time for the "consumer" (main thread) to do its part
258 waitConditionMutex.lock();
259 authRequestBufferNotEmpty.wakeAll();
260 waitConditionMutex.unlock();
261
262 // note that we don't need to handle waking this thread back up - that's done automatically by QgsNetworkAccessManager
263 };
264
265 QMetaObject::Connection authRequestConnection;
266 QMetaObject::Connection proxyAuthenticationConnection;
267#ifndef QT_NO_SSL
268 QMetaObject::Connection sslErrorsConnection;
269#endif
270
271 if ( requestMadeFromMainThread )
272 {
273 authRequestConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::authRequestOccurred, this, resumeMainThread, Qt::DirectConnection );
274 proxyAuthenticationConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::proxyAuthenticationRequired, this, resumeMainThread, Qt::DirectConnection );
275
276#ifndef QT_NO_SSL
277 sslErrorsConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::sslErrorsOccurred, this, resumeMainThread, Qt::DirectConnection );
278#endif
279 }
280 QEventLoop loop;
281 // connecting to aboutToQuit avoids an on-going request to remain stalled
282 // when QThreadPool::globalInstance()->waitForDone()
283 // is called at process termination
284 connect( qApp, &QCoreApplication::aboutToQuit, &loop, &QEventLoop::quit, Qt::DirectConnection );
285 connect( this, &QgsBlockingNetworkRequest::finished, &loop, &QEventLoop::quit, Qt::DirectConnection );
286 loop.exec();
287
288 if ( requestMadeFromMainThread )
289 {
290 // event loop exited - need to disconnect as to not leave functor hanging to receive signals in future
291 disconnect( authRequestConnection );
292 disconnect( proxyAuthenticationConnection );
293#ifndef QT_NO_SSL
294 disconnect( sslErrorsConnection );
295#endif
296 }
297 }
298
299 if ( requestMadeFromMainThread )
300 {
301 waitConditionMutex.lock();
302 threadFinished = true;
303 authRequestBufferNotEmpty.wakeAll();
304 waitConditionMutex.unlock();
305 }
306 };
307
308 if ( requestMadeFromMainThread )
309 {
310 auto downloaderThread = std::make_unique<DownloaderThread>( downloaderFunction );
311 downloaderThread->start();
312
313 while ( true )
314 {
315 waitConditionMutex.lock();
316 if ( threadFinished )
317 {
318 waitConditionMutex.unlock();
319 break;
320 }
321 authRequestBufferNotEmpty.wait( &waitConditionMutex );
322
323 // If the downloader thread wakes us (the main thread) up and is not yet finished
324 // then it has "produced" an authentication request which we need to now "consume".
325 // The processEvents() call gives the auth manager the chance to show a dialog and
326 // once done with that, we can wake the downloaderThread again and continue the download.
327 if ( !threadFinished )
328 {
329 waitConditionMutex.unlock();
330
331 QgsApplication::processEvents();
332 // we don't need to wake up the worker thread - it will automatically be woken when
333 // the auth request has been dealt with by QgsNetworkAccessManager
334 }
335 else
336 {
337 waitConditionMutex.unlock();
338 }
339 }
340 // wait for thread to gracefully exit
341 downloaderThread->wait();
342 }
343 else
344 {
345 downloaderFunction();
346 }
347 return mErrorCode;
348}
349
351{
352 mIsAborted = true;
353 if ( mReply )
354 {
355 mReply->deleteLater();
356 mReply = nullptr;
357 }
358}
359
360void QgsBlockingNetworkRequest::replyProgress( qint64 bytesReceived, qint64 bytesTotal )
361{
362 QgsDebugMsgLevel( u"%1 of %2 bytes downloaded."_s.arg( bytesReceived ).arg( bytesTotal < 0 ? u"unknown number of"_s : QString::number( bytesTotal ) ), 2 );
363
364 if ( bytesReceived != 0 )
365 mGotNonEmptyResponse = true;
366
367 if ( !mIsAborted && mReply && ( !mFeedback || !mFeedback->isCanceled() ) )
368 {
369 if ( mReply->error() == QNetworkReply::NoError )
370 {
371 const QVariant redirect = mReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
372 if ( !QgsVariantUtils::isNull( redirect ) )
373 {
374 // We don't want to emit downloadProgress() for a redirect
375 return;
376 }
377 }
378 }
379
380 if ( mMethod == Qgis::HttpMethod::Put || mMethod == Qgis::HttpMethod::Post )
381 emit uploadProgress( bytesReceived, bytesTotal );
382 else
383 emit downloadProgress( bytesReceived, bytesTotal );
384}
385
386void QgsBlockingNetworkRequest::replyFinished()
387{
388 if ( !mIsAborted && mReply )
389 {
390 if ( mReply->error() == QNetworkReply::NoError && ( !mFeedback || !mFeedback->isCanceled() ) )
391 {
392 QgsDebugMsgLevel( u"reply OK"_s, 2 );
393 const QVariant redirect = mReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
394 if ( !QgsVariantUtils::isNull( redirect ) )
395 {
396 QgsDebugMsgLevel( u"Request redirected."_s, 2 );
397
398 const QUrl &toUrl = redirect.toUrl();
399 mReply->request();
400 if ( toUrl == mReply->url() )
401 {
402 mErrorMessage = tr( "Redirect loop detected: %1" ).arg( toUrl.toString() );
403 if ( !mFlags.testFlag( Qgis::NetworkRequestFlag::DisableMessageLogging ) )
404 {
405 QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
406 }
407 mReplyContent.clear();
408 }
409 else
410 {
411 QNetworkRequest request( toUrl );
412
413 if ( !mAuthCfg.isEmpty() && !QgsApplication::authManager()->updateNetworkRequest( request, mAuthCfg ) )
414 {
415 mReplyContent.clear();
416 mErrorMessage = errorMessageFailedAuth();
417 mErrorCode = NetworkError;
418 if ( !mFlags.testFlag( Qgis::NetworkRequestFlag::DisableMessageLogging ) )
419 {
420 QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
421 }
422 emit finished();
424 emit downloadFinished();
426 return;
427 }
428
429 request.setAttribute( QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::ManualRedirectPolicy );
430 request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mForceRefresh ? QNetworkRequest::AlwaysNetwork : QNetworkRequest::PreferCache );
431 request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
432
433 // if that was a range request, use the same range for the redirected request
434 if ( mReply->request().hasRawHeader( "Range" ) )
435 request.setRawHeader( "Range", mReply->request().rawHeader( "Range" ) );
436
437 mReply->deleteLater();
438 mReply = nullptr;
439
440 QgsDebugMsgLevel( u"redirected: %1 forceRefresh=%2"_s.arg( redirect.toString() ).arg( mForceRefresh ), 2 );
441
442 sendRequestToNetworkAccessManager( request );
443
444 if ( mFeedback )
445 connect( mFeedback, &QgsFeedback::canceled, mReply, &QNetworkReply::abort );
446
447 if ( !mAuthCfg.isEmpty() && !QgsApplication::authManager()->updateNetworkReply( mReply, mAuthCfg ) )
448 {
449 mReplyContent.clear();
450 mErrorMessage = errorMessageFailedAuth();
451 mErrorCode = NetworkError;
452 if ( !mFlags.testFlag( Qgis::NetworkRequestFlag::DisableMessageLogging ) )
453 {
454 QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
455 }
456 emit finished();
458 emit downloadFinished();
460 return;
461 }
462
463 connect( mReply, &QNetworkReply::finished, this, &QgsBlockingNetworkRequest::replyFinished, Qt::DirectConnection );
464 connect( mReply, &QNetworkReply::downloadProgress, this, &QgsBlockingNetworkRequest::replyProgress, Qt::DirectConnection );
465 connect( mReply, &QNetworkReply::uploadProgress, this, &QgsBlockingNetworkRequest::replyProgress, Qt::DirectConnection );
466
467 if ( request.hasRawHeader( "Range" ) )
468 connect( mReply, &QNetworkReply::metaDataChanged, this, &QgsBlockingNetworkRequest::abortIfNotPartialContentReturned, Qt::DirectConnection );
469
470 return;
471 }
472 }
473 else
474 {
475 const QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
476
477 if ( nam->cache() )
478 {
479 QNetworkCacheMetaData cmd = nam->cache()->metaData( mReply->request().url() );
480
481 QNetworkCacheMetaData::RawHeaderList hl;
482 const auto constRawHeaders = cmd.rawHeaders();
483 for ( const QNetworkCacheMetaData::RawHeader &h : constRawHeaders )
484 {
485 if ( h.first != "Cache-Control" )
486 hl.append( h );
487 }
488 cmd.setRawHeaders( hl );
489
490 QgsDebugMsgLevel( u"expirationDate:%1"_s.arg( cmd.expirationDate().toString() ), 2 );
491 if ( cmd.expirationDate().isNull() )
492 {
493 cmd.setExpirationDate( QDateTime::currentDateTime().addSecs( mExpirationSec ) );
494 }
495
496 nam->cache()->updateMetaData( cmd );
497 }
498 else
499 {
500 QgsDebugMsgLevel( u"No cache!"_s, 2 );
501 }
502
503#ifdef QGISDEBUG
504 const bool fromCache = mReply->attribute( QNetworkRequest::SourceIsFromCacheAttribute ).toBool();
505 QgsDebugMsgLevel( u"Reply was cached: %1"_s.arg( fromCache ), 2 );
506#endif
507
508 mReplyContent = QgsNetworkReplyContent( mReply );
509 const QByteArray content = mReply->readAll();
510 if ( !( mRequestFlags & RequestFlag::EmptyResponseIsValid ) && content.isEmpty() && !mGotNonEmptyResponse && mMethod == Qgis::HttpMethod::Get && ( !mFeedback || !mFeedback->isCanceled() ) )
511 {
512 mErrorMessage = tr( "empty response: %1" ).arg( mReply->errorString() );
513 mErrorCode = ServerExceptionError;
514 if ( !mFlags.testFlag( Qgis::NetworkRequestFlag::DisableMessageLogging ) )
515 {
516 QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
517 }
518 }
519 mReplyContent.setContent( content );
520 }
521 }
522 else
523 {
524 if ( mReply->error() != QNetworkReply::OperationCanceledError && ( !mFeedback || !mFeedback->isCanceled() ) )
525 {
526 mErrorMessage = mReply->errorString();
527 mErrorCode = ServerExceptionError;
528 if ( !mFlags.testFlag( Qgis::NetworkRequestFlag::DisableMessageLogging ) )
529 {
530 QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
531 }
532 }
533 mReplyContent = QgsNetworkReplyContent( mReply );
534 mReplyContent.setContent( mReply->readAll() );
535 }
536 }
537 if ( mTimedout )
538 mErrorCode = TimeoutError;
539
540 if ( mReply )
541 {
542 mReply->deleteLater();
543 mReply = nullptr;
544 }
545
546 emit finished();
548 emit downloadFinished();
550}
551
552QString QgsBlockingNetworkRequest::errorMessageFailedAuth()
553{
554 return tr( "network request update failed for authentication config" );
555}
556
557void QgsBlockingNetworkRequest::abortIfNotPartialContentReturned()
558{
559 if ( mReply && mReply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt() == 200 )
560 {
561 // We're expecting a 206 - Partial Content but the server returned 200
562 // It seems it does not support range requests and is returning the whole file!
563 mReply->abort();
564 mErrorMessage = tr( "The server does not support range requests" );
565 mErrorCode = ServerExceptionError;
566 }
567}
@ DisableMessageLogging
If present, indicates that no message logging should be performed when network errors are encountered...
Definition qgis.h:188
QFlags< NetworkRequestFlag > NetworkRequestFlags
Flags controlling behavior of network requests.
Definition qgis.h:197
HttpMethod
Different methods of HTTP requests.
Definition qgis.h:1138
@ Post
POST method.
Definition qgis.h:1140
@ Patch
PATCH method.
Definition qgis.h:1144
@ Head
HEAD method.
Definition qgis.h:1141
@ Get
GET method.
Definition qgis.h:1139
@ Put
PUT method.
Definition qgis.h:1142
@ Delete
DELETE method.
Definition qgis.h:1143
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkRequest with an authentication config.
bool updateNetworkReply(QNetworkReply *reply, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkReply with an authentication config (used to skip known SSL errors,...
ErrorCode put(QNetworkRequest &request, QIODevice *data, QgsFeedback *feedback=nullptr)
Performs a "put" operation on the specified request, using the given data.
QgsBlockingNetworkRequest(Qgis::NetworkRequestFlags flags=Qgis::NetworkRequestFlags())
Constructor for QgsBlockingNetworkRequest.
void uploadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when when data are sent during a request.
Qgis::NetworkRequestFlags flags() const
Returns the network request flags.
ErrorCode head(QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
Performs a "head" operation on the specified request.
void abort()
Aborts the network request immediately.
Q_DECL_DEPRECATED void downloadFinished()
Emitted once a request has finished downloading.
ErrorCode post(QNetworkRequest &request, QIODevice *data, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
Performs a "post" operation on the specified request, using the given data.
ErrorCode deleteResource(QNetworkRequest &request, QgsFeedback *feedback=nullptr)
Performs a "delete" operation on the specified request.
void finished()
Emitted once a request has finished.
void setAuthCfg(const QString &authCfg)
Sets the authentication config id which should be used during the request.
QString authCfg() const
Returns the authentication config id which will be used during the request.
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when when data arrives during a request.
ErrorCode get(QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr, RequestFlags requestFlags=QgsBlockingNetworkRequest::RequestFlags())
Performs a "get" operation on the specified request.
@ EmptyResponseIsValid
Do not generate an error if getting an empty response (e.g. HTTP 204).
ErrorCode patch(QNetworkRequest &request, QIODevice *data, QgsFeedback *feedback=nullptr)
Performs a "patch" operation on the specified request, using the given data.
@ NetworkError
A network error occurred.
@ ServerExceptionError
An exception was raised by the server.
@ NoError
No error was encountered.
@ TimeoutError
Timeout was reached before a reply was received.
QgsNetworkReplyContent reply() const
Returns the content of the network reply, after a get(), post(), head() or put() request has been mad...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
void canceled()
Internal routines can connect to this signal if they use event loop.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
void requestTimedOut(QgsNetworkRequestParameters request)
Emitted when a network request has timed out.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:8462
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:8461
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:80
#define QgsDebugError(str)
Definition qgslogger.h:71