QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
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 <QByteArray>
21#include <QNetworkReply>
22
28class CORE_EXPORT QgsNetworkReplyContent
29{
30 public:
35
39 explicit QgsNetworkReplyContent( QNetworkReply *reply );
40
44 void clear();
45
55 QVariant attribute( QNetworkRequest::Attribute code ) const;
56
57#ifndef SIP_RUN
58
65 QMap< QNetworkRequest::Attribute, QVariant > attributes() const { return mAttributes; }
66#endif
67
74 QNetworkReply::NetworkError error() const { return mError; }
75
82 QString errorString() const { return mErrorString; }
83
84#ifndef SIP_RUN
85 typedef QPair<QByteArray, QByteArray> RawHeaderPair;
86
94 const QList<RawHeaderPair> &rawHeaderPairs() const { return mRawHeaderPairs; }
95#endif
96
103 bool hasRawHeader( const QByteArray &headerName ) const;
104
111 QList<QByteArray> rawHeaderList() const;
112
120 QByteArray rawHeader( const QByteArray &headerName ) const;
121
125 int requestId() const { return mRequestId; }
126
130 QNetworkRequest request() const { return mRequest; }
131
138 void setContent( const QByteArray &content ) { mContent = content; }
139
148 QByteArray content() const { return mContent; }
149
155 static QString extractFilenameFromContentDispositionHeader( QNetworkReply *reply );
156
162 static QString extractFileNameFromContentDispositionHeader( const QString &header );
163
164 private:
165 QNetworkReply::NetworkError mError = QNetworkReply::NoError;
166 QString mErrorString;
167 QList<RawHeaderPair> mRawHeaderPairs;
168 QMap< QNetworkRequest::Attribute, QVariant > mAttributes;
169 int mRequestId = -1;
170 QNetworkRequest mRequest;
171 QByteArray mContent;
172};
173
174#endif // QGSNETWORKREPLY_H
const QList< RawHeaderPair > & rawHeaderPairs() const
Returns the list of raw header pairs in the reply.
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code.
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.
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.
QPair< QByteArray, QByteArray > RawHeaderPair
QNetworkRequest request() const
Returns the original network request.