QGIS API Documentation  3.6.0-Noosa (5873452)
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 
35  QgsNetworkReplyContent() = default;
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
QNetworkReply::NetworkError error() const
Returns the reply&#39;s error message, or QNetworkReply::NoError if no error was encountered.
int requestId() const
Returns the unique ID identifying the original request which this response was formed from...
QMap< QNetworkRequest::Attribute, QVariant > attributes() const
Returns a list of valid attributes received in the reply.
QString errorString() const
Returns the error text for the reply, or an empty string if no error was encountered.
QPair< QByteArray, QByteArray > RawHeaderPair
QByteArray content() const
Returns the reply content.
void setContent(const QByteArray &content)
Sets the reply content.
Encapsulates a network reply within a container which is inexpensive to copy and safe to pass between...
QNetworkRequest request() const
Returns the original network request.
const QList< RawHeaderPair > & rawHeaderPairs() const
Returns the list of raw header pairs in the reply.