diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index 9334b01de6a..0613a65c34d 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -653,6 +653,19 @@ const QList& QNetworkReply::rawHeaderPairs() const return d->rawHeaders; } +/*! + \since 6.8 + + Returns headers that were sent by the remote server. + + \sa setHeaders(), QNetworkRequest::setAttribute(), QNetworkRequest::Attribute +*/ +QHttpHeaders QNetworkReply::headers() const +{ + Q_D(const QNetworkReply); + return d->headers(); +} + /*! Returns a list of headers fields that were sent by the remote server, in the order that they were sent. Duplicate headers are @@ -887,6 +900,45 @@ void QNetworkReply::setUrl(const QUrl &url) d->url = url; } +/*! + \since 6.8 + + Sets \a newHeaders as headers in this network reply, overriding + any previously set headers. + + If some headers correspond to the known headers, they will be + parsed and the corresponding parsed form will also be set. + + \sa headers(), QNetworkRequest::KnownHeaders +*/ +void QNetworkReply::setHeaders(const QHttpHeaders &newHeaders) +{ + Q_D(QNetworkReply); + d->setHeaders(newHeaders); +} + +/*! + \overload + \since 6.8 +*/ +void QNetworkReply::setHeaders(QHttpHeaders &&newHeaders) +{ + Q_D(QNetworkReply); + d->setHeaders(std::move(newHeaders)); +} + +/*! + \since 6.8 + + Sets the header \a name to be of value \a value. If \a + name was previously set, it is overridden. +*/ +void QNetworkReply::setWellKnownHeader(QHttpHeaders::WellKnownHeader name, const QByteArray &value) +{ + Q_D(QNetworkReply); + d->setHeader(name, value); +} + /*! Sets the known header \a header to be of value \a value. The corresponding raw form of the header will be set as well. diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index 390a6f2f516..48ec0397c69 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -109,6 +109,7 @@ public: typedef QPair RawHeaderPair; const QList& rawHeaderPairs() const; + QHttpHeaders headers() const; // attributes QVariant attribute(QNetworkRequest::Attribute code) const; @@ -152,6 +153,9 @@ protected: void setUrl(const QUrl &url); void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); void setRawHeader(const QByteArray &headerName, const QByteArray &value); + void setHeaders(const QHttpHeaders &newHeaders); + void setHeaders(QHttpHeaders &&newHeaders); + void setWellKnownHeader(QHttpHeaders::WellKnownHeader name, const QByteArray &value); void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); #if QT_CONFIG(ssl)