QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsnetworkreply.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnetworkreply.h
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 #ifndef QGSNETWORKREPLY_H
16 #define QGSNETWORKREPLY_H
17 
18 #include "qgis_core.h"
19 
20 #include <QNetworkReply>
21 #include <QByteArray>
22 
28 class CORE_EXPORT QgsNetworkReplyContent
29 {
30  public:
31 
36 
40  explicit QgsNetworkReplyContent( QNetworkReply *reply );
41 
45  void clear();
46 
56  QVariant attribute( QNetworkRequest::Attribute code ) const;
57 
58 #ifndef SIP_RUN
59 
66  QMap< QNetworkRequest::Attribute, QVariant > attributes() const { return mAttributes; }
67 #endif
68 
75  QNetworkReply::NetworkError error() const
76  {
77  return mError;
78  }
79 
86  QString errorString() const
87  {
88  return mErrorString;
89  }
90 
91 #ifndef SIP_RUN
92  typedef QPair<QByteArray, QByteArray> RawHeaderPair;
93 
101  const QList<RawHeaderPair> &rawHeaderPairs() const
102  {
103  return mRawHeaderPairs;
104  }
105 #endif
106 
113  bool hasRawHeader( const QByteArray &headerName ) const;
114 
121  QList<QByteArray> rawHeaderList() const;
122 
130  QByteArray rawHeader( const QByteArray &headerName ) const;
131 
135  int requestId() const { return mRequestId; }
136 
140  QNetworkRequest request() const { return mRequest; }
141 
148  void setContent( const QByteArray &content ) { mContent = content; }
149 
158  QByteArray content() const { return mContent; }
159 
160  private:
161 
162  QNetworkReply::NetworkError mError = QNetworkReply::NoError;
163  QString mErrorString;
164  QList<RawHeaderPair> mRawHeaderPairs;
165  QMap< QNetworkRequest::Attribute, QVariant > mAttributes;
166  int mRequestId = -1;
167  QNetworkRequest mRequest;
168  QByteArray mContent;
169 };
170 
171 #endif // QGSNETWORKREPLY_H
QgsNetworkReplyContent::error
QNetworkReply::NetworkError error() const
Returns the reply's error message, or QNetworkReply::NoError if no error was encountered.
Definition: qgsnetworkreply.h:75
QgsNetworkReplyContent::request
QNetworkRequest request() const
Returns the original network request.
Definition: qgsnetworkreply.h:140
QgsNetworkReplyContent::RawHeaderPair
QPair< QByteArray, QByteArray > RawHeaderPair
Definition: qgsnetworkreply.h:92
QgsNetworkReplyContent::rawHeaderPairs
const QList< RawHeaderPair > & rawHeaderPairs() const
Returns the list of raw header pairs in the reply.
Definition: qgsnetworkreply.h:101
QgsNetworkReplyContent::QgsNetworkReplyContent
QgsNetworkReplyContent()=default
Default constructor for an empty reply.
QgsNetworkReplyContent::errorString
QString errorString() const
Returns the error text for the reply, or an empty string if no error was encountered.
Definition: qgsnetworkreply.h:86
QgsNetworkReplyContent::attributes
QMap< QNetworkRequest::Attribute, QVariant > attributes() const
Returns a list of valid attributes received in the reply.
Definition: qgsnetworkreply.h:66
QgsNetworkReplyContent::content
QByteArray content() const
Returns the reply content.
Definition: qgsnetworkreply.h:158
QgsNetworkReplyContent
Encapsulates a network reply within a container which is inexpensive to copy and safe to pass between...
Definition: qgsnetworkreply.h:29
QgsNetworkReplyContent::setContent
void setContent(const QByteArray &content)
Sets the reply content.
Definition: qgsnetworkreply.h:148
QgsNetworkReplyContent::requestId
int requestId() const
Returns the unique ID identifying the original request which this response was formed from.
Definition: qgsnetworkreply.h:135