QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsnetworkreply.cpp
Go to the documentation of this file.
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 
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 
39 {
40  *this = QgsNetworkReplyContent();
41 }
42 
43 QVariant QgsNetworkReplyContent::attribute( QNetworkRequest::Attribute code ) const
44 {
45  return mAttributes.value( code );
46 }
47 
48 bool 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 
58 QList<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 
69 QByteArray 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 }
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code.
QgsNetworkReplyContent()=default
Default constructor for an empty reply.
bool hasRawHeader(const QByteArray &headerName) const
Returns true if the reply contains a header with the specified headerName.
QByteArray rawHeader(const QByteArray &headerName) const
Returns the content of the header with the specified headerName, or an empty QByteArray if the specif...
QList< QByteArray > rawHeaderList() const
Returns a list of raw header names contained within the reply.
void clear()
Clears the reply, resetting it back to a default, empty reply.
int requestId() const
Returns the unique ID identifying the original request which this response was formed from.