17#include <QNetworkReply>
18#include <QRegularExpression>
19#include <QRegularExpressionMatch>
22 : mError( reply->error() )
23 , mErrorString( reply->errorString() )
24 , mRawHeaderPairs( reply->rawHeaderPairs() )
25 , mRequest( reply->request() )
27 const int maxAttribute =
static_cast< int >( QNetworkRequest::Http2DirectAttribute );
28 for (
int i = 0; i <= maxAttribute; ++i )
30 if ( reply->attribute(
static_cast< QNetworkRequest::Attribute
>( i ) ).isValid() )
31 mAttributes[
static_cast< QNetworkRequest::Attribute
>( i ) ] = reply->attribute(
static_cast< QNetworkRequest::Attribute
>( i ) );
35 const int requestId = reply->property(
"requestId" ).toInt( &ok );
47 return mAttributes.value( code );
52 for (
auto &header : mRawHeaderPairs )
54 if ( ! QString::fromLocal8Bit( header.first ).compare( QString::fromLocal8Bit( headerName ), Qt::CaseInsensitive ) )
62 QList< QByteArray > res;
63 res.reserve( mRawHeaderPairs.length() );
64 for (
auto &header : mRawHeaderPairs )
73 for (
auto &header : mRawHeaderPairs )
75 if ( ! QString::fromLocal8Bit( header.first ).compare( QString::fromLocal8Bit( headerName ), Qt::CaseInsensitive ) )
91 const thread_local QRegularExpression rx( QStringLiteral( R
"""(filename[^;\n]*=\s*(UTF-\d['"]*)?((['"]).*?[.]$\2|[^;\n]*)?)""" ), QRegularExpression::PatternOption::CaseInsensitiveOption );
93 QRegularExpressionMatchIterator i = rx.globalMatch( header, 0 );
98 const QRegularExpressionMatch match = i.next();
99 res = match.captured( 2 );
102 if ( res.startsWith(
'"' ) )
105 if ( res.endsWith(
'"' ) )
108 if ( !res.isEmpty() )
110 res = QUrl::fromPercentEncoding( res.toUtf8() );
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code.
QgsNetworkReplyContent()=default
Default constructor for an empty reply.
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.
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.