Skip to content
Permalink
Browse files

Make request a member of reply

  • Loading branch information
nyalldawson committed Jan 23, 2019
1 parent aa170ad commit e50d9a1673de5612a930291f777bd9421b3ab6b9
@@ -102,6 +102,11 @@ empty QByteArray if the specified header was not found in the reply.
int requestId() const;
%Docstring
Returns the unique ID identifying the original request which this response was formed from.
%End

QNetworkRequest request() const;
%Docstring
Returns the original network request.
%End

};
@@ -20,6 +20,7 @@ QgsNetworkReplyContent::QgsNetworkReplyContent( QNetworkReply *reply )
: mError( reply->error() )
, mErrorString( reply->errorString() )
, mRawHeaderPairs( reply->rawHeaderPairs() )
, mRequest( reply->request() )
{
int maxAttribute = static_cast< int >( QNetworkRequest::RedirectPolicyAttribute );
#if QT_VERSION >= QT_VERSION_CHECK( 5, 11, 0 )
@@ -133,13 +133,19 @@ class CORE_EXPORT QgsNetworkReplyContent
*/
int requestId() const { return mRequestId; }

/**
* Returns the original network request.
*/
QNetworkRequest request() const { return mRequest; }

private:

QNetworkReply::NetworkError mError = QNetworkReply::NoError;
QString mErrorString;
QList<RawHeaderPair> mRawHeaderPairs;
QMap< QNetworkRequest::Attribute, QVariant > mAttributes;
int mRequestId = -1;
QNetworkRequest mRequest;
};

#endif // QGSNETWORKREPLY_H
@@ -65,18 +65,19 @@ void TestQgsNetworkAccessManager::fetchEmptyUrl()
bool loaded = false;
bool gotRequestAboutToBeCreatedSignal = false;
int requestId = -1;
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( QgsNetworkRequestParameters params )
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( const QgsNetworkRequestParameters & params )
{
gotRequestAboutToBeCreatedSignal = true;
requestId = params.requestId();
QVERIFY( requestId > 0 );
QCOMPARE( params.operation(), QNetworkAccessManager::GetOperation );
QCOMPARE( params.request().url(), QUrl() );
} );
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkReplyContent >::of( &QgsNetworkAccessManager::finished ), &context, [&]( QgsNetworkReplyContent reply )
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkReplyContent >::of( &QgsNetworkAccessManager::finished ), &context, [&]( const QgsNetworkReplyContent & reply )
{
QCOMPARE( reply.errorString(), QStringLiteral( "Protocol \"\" is unknown" ) );
QCOMPARE( reply.requestId(), requestId );
QCOMPARE( reply.request().url(), QUrl() );
loaded = true;
} );
QgsNetworkAccessManager::instance()->get( QNetworkRequest( QUrl() ) );
@@ -96,18 +97,20 @@ void TestQgsNetworkAccessManager::fetchBadUrl()
bool loaded = false;
bool gotRequestAboutToBeCreatedSignal = false;
int requestId = -1;
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( QgsNetworkRequestParameters params )
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( const QgsNetworkRequestParameters & params )
{
gotRequestAboutToBeCreatedSignal = true;
requestId = params.requestId();
QVERIFY( requestId > 0 );
QCOMPARE( params.operation(), QNetworkAccessManager::GetOperation );
QCOMPARE( params.request().url(), QUrl( QStringLiteral( "http://x" ) ) );
} );
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkReplyContent >::of( &QgsNetworkAccessManager::finished ), &context, [&]( QgsNetworkReplyContent reply )
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkReplyContent >::of( &QgsNetworkAccessManager::finished ), &context, [&]( const QgsNetworkReplyContent & reply )
{
QCOMPARE( reply.errorString(), QStringLiteral( "Host x not found" ) );
QCOMPARE( reply.requestId(), requestId );
QCOMPARE( reply.request().url(), QUrl( QStringLiteral( "http://x" ) ) );

loaded = true;
} );
QgsNetworkAccessManager::instance()->get( QNetworkRequest( QUrl( QStringLiteral( "http://x" ) ) ) );
@@ -129,19 +132,20 @@ void TestQgsNetworkAccessManager::fetchEncodedContent()
bool gotRequestAboutToBeCreatedSignal = false;
int requestId = -1;
QUrl u = QUrl::fromLocalFile( QStringLiteral( TEST_DATA_DIR ) + '/' + "encoded_html.html" );
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( QgsNetworkRequestParameters params )
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( const QgsNetworkRequestParameters & params )
{
gotRequestAboutToBeCreatedSignal = true;
requestId = params.requestId();
QVERIFY( requestId > 0 );
QCOMPARE( params.operation(), QNetworkAccessManager::GetOperation );
QCOMPARE( params.request().url(), u );
} );
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkReplyContent >::of( &QgsNetworkAccessManager::finished ), &context, [&]( QgsNetworkReplyContent reply )
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkReplyContent >::of( &QgsNetworkAccessManager::finished ), &context, [&]( const QgsNetworkReplyContent & reply )
{
QCOMPARE( reply.error(), QNetworkReply::NoError );
QCOMPARE( reply.requestId(), requestId );
QVERIFY( reply.rawHeaderList().contains( "Content-Length" ) );
QCOMPARE( reply.request().url(), u );
loaded = true;
} );
QgsNetworkAccessManager::instance()->get( QNetworkRequest( u ) );

0 comments on commit e50d9a1

Please sign in to comment.
You can’t perform that action at this time.