1 /*************************************************************************** 2 qgsnetworkreply.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 16 #include "qgsnetworkreply.h" 17 #include <QNetworkReply> 18 QgsNetworkReplyContent(QNetworkReply * reply)19QgsNetworkReplyContent::QgsNetworkReplyContent( QNetworkReply *reply ) 20 : mError( reply->error() ) 21 , mErrorString( reply->errorString() ) 22 , mRawHeaderPairs( reply->rawHeaderPairs() ) 23 , mRequest( reply->request() ) 24 { 25 const int maxAttribute = static_cast< int >( QNetworkRequest::Http2DirectAttribute ); 26 for ( int i = 0; i <= maxAttribute; ++i ) 27 { 28 if ( reply->attribute( static_cast< QNetworkRequest::Attribute>( i ) ).isValid() ) 29 mAttributes[ static_cast< QNetworkRequest::Attribute>( i ) ] = reply->attribute( static_cast< QNetworkRequest::Attribute>( i ) ); 30 } 31 32 bool ok = false; 33 const int requestId = reply->property( "requestId" ).toInt( &ok ); 34 if ( ok ) 35 mRequestId = requestId; 36 } 37 clear()38void QgsNetworkReplyContent::clear() 39 { 40 *this = QgsNetworkReplyContent(); 41 } 42 attribute(QNetworkRequest::Attribute code) const43QVariant QgsNetworkReplyContent::attribute( QNetworkRequest::Attribute code ) const 44 { 45 return mAttributes.value( code ); 46 } 47 hasRawHeader(const QByteArray & headerName) const48bool QgsNetworkReplyContent::hasRawHeader( const QByteArray &headerName ) const 49 { 50 for ( auto &header : mRawHeaderPairs ) 51 { 52 if ( header.first == headerName ) 53 return true; 54 } 55 return false; 56 } 57 rawHeaderList() const58QList<QByteArray> QgsNetworkReplyContent::rawHeaderList() const 59 { 60 QList< QByteArray > res; 61 res.reserve( mRawHeaderPairs.length() ); 62 for ( auto &header : mRawHeaderPairs ) 63 { 64 res << header.first; 65 } 66 return res; 67 } 68 rawHeader(const QByteArray & headerName) const69QByteArray QgsNetworkReplyContent::rawHeader( const QByteArray &headerName ) const 70 { 71 for ( auto &header : mRawHeaderPairs ) 72 { 73 if ( header.first == headerName ) 74 return header.second; 75 } 76 return QByteArray(); 77 } 78