QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
28class 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
165 static QString extractFilenameFromContentDispositionHeader( QNetworkReply *reply );
166
172 static QString extractFileNameFromContentDispositionHeader( const QString &header );
173
174 private:
175
176 QNetworkReply::NetworkError mError = QNetworkReply::NoError;
177 QString mErrorString;
178 QList<RawHeaderPair> mRawHeaderPairs;
179 QMap< QNetworkRequest::Attribute, QVariant > mAttributes;
180 int mRequestId = -1;
181 QNetworkRequest mRequest;
182 QByteArray mContent;
183};
184
185#endif // QGSNETWORKREPLY_H
Encapsulates a network reply within a container which is inexpensive to copy and safe to pass between...
const QList< RawHeaderPair > & rawHeaderPairs() const
Returns the list of raw header pairs in the reply.
QgsNetworkReplyContent()=default
Default constructor for an empty reply.
QString errorString() const
Returns the error text for the reply, or an empty string if no error was encountered.
void setContent(const QByteArray &content)
Sets the reply content.
QByteArray content() const
Returns the reply content.
QNetworkReply::NetworkError error() const
Returns the reply's error message, or QNetworkReply::NoError if no error was encountered.
QMap< QNetworkRequest::Attribute, QVariant > attributes() const
Returns a list of valid attributes received in the reply.
int requestId() const
Returns the unique ID identifying the original request which this response was formed from.
QPair< QByteArray, QByteArray > RawHeaderPair
QNetworkRequest request() const
Returns the original network request.