18#include <QNetworkReply>
19#include <QRegularExpression>
20#include <QRegularExpressionMatch>
23 : mError( reply->
error() )
28 const int maxAttribute =
static_cast< int >( QNetworkRequest::Http2DirectAttribute );
29 for (
int i = 0; i <= maxAttribute; ++i )
31 if ( reply->attribute(
static_cast< QNetworkRequest::Attribute
>( i ) ).isValid() )
32 mAttributes[
static_cast< QNetworkRequest::Attribute
>( i ) ] = reply->attribute(
static_cast< QNetworkRequest::Attribute
>( i ) );
36 const int requestId = reply->property(
"requestId" ).toInt( &ok );
48 return mAttributes.value( code );
53 for (
auto &header : mRawHeaderPairs )
55 if ( ! QString::fromLocal8Bit( header.first ).compare( QString::fromLocal8Bit( headerName ), Qt::CaseInsensitive ) )
63 QList< QByteArray > res;
64 res.reserve( mRawHeaderPairs.length() );
65 for (
auto &header : mRawHeaderPairs )
74 for (
auto &header : mRawHeaderPairs )
76 if ( ! QString::fromLocal8Bit( header.first ).compare( QString::fromLocal8Bit( headerName ), Qt::CaseInsensitive ) )
92 const thread_local QRegularExpression rx( QStringLiteral( R
"""(filename[^;\n]*=\s*(UTF-\d['"]*)?((['"]).*?[.]$\2|[^;\n]*)?)""" ), QRegularExpression::PatternOption::CaseInsensitiveOption );
94 QRegularExpressionMatchIterator i = rx.globalMatch( header, 0 );
99 const QRegularExpressionMatch match = i.next();
100 res = match.captured( 2 );
103 if ( res.startsWith(
'"' ) )
106 if ( res.endsWith(
'"' ) )
109 if ( !res.isEmpty() )
111 res = QUrl::fromPercentEncoding( res.toUtf8() );
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.
bool hasRawHeader(const QByteArray &headerName) const
Returns true if the reply contains a header with the specified headerName.
static QString extractFilenameFromContentDispositionHeader(QNetworkReply *reply)
Extracts the filename component of the content disposition header from a network reply.
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.
QNetworkReply::NetworkError error() const
Returns the reply's error message, or QNetworkReply::NoError if no error was encountered.
void clear()
Clears the reply, resetting it back to a default, empty reply.
static QString extractFileNameFromContentDispositionHeader(const QString &header)
Extracts the filename component of the content disposition header from the header.
int requestId() const
Returns the unique ID identifying the original request which this response was formed from.
QNetworkRequest request() const
Returns the original network request.