Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
|
#include <qhttpheaders.h>
Public Member Functions | |
Q_NETWORK_EXPORT | QHttpHeaders () noexcept |
Creates a new QHttpHeaders object. | |
Q_NETWORK_EXPORT | ~QHttpHeaders () |
Disposes of the headers object. | |
Q_NETWORK_EXPORT | QHttpHeaders (const QHttpHeaders &other) |
Creates a copy of other. | |
QHttpHeaders (QHttpHeaders &&other) noexcept=default | |
Move-constructs the object from other, which will be left \l{isEmpty()}{empty}. | |
Q_NETWORK_EXPORT QHttpHeaders & | operator= (const QHttpHeaders &other) |
Assigns the contents of other and returns a reference to this object. | |
void | swap (QHttpHeaders &other) noexcept |
Swaps this QHttpHeaders with other. | |
Q_NETWORK_EXPORT bool | append (QAnyStringView name, QAnyStringView value) |
Appends a header entry with name and value and returns true if successful. | |
Q_NETWORK_EXPORT bool | append (WellKnownHeader name, QAnyStringView value) |
Q_NETWORK_EXPORT bool | insert (qsizetype i, QAnyStringView name, QAnyStringView value) |
Inserts a header entry at index i, with name and value. | |
Q_NETWORK_EXPORT bool | insert (qsizetype i, WellKnownHeader name, QAnyStringView value) |
Q_NETWORK_EXPORT bool | replace (qsizetype i, QAnyStringView name, QAnyStringView newValue) |
Replaces the header entry at index i, with name and newValue. | |
Q_NETWORK_EXPORT bool | replace (qsizetype i, WellKnownHeader name, QAnyStringView newValue) |
Q_NETWORK_EXPORT bool | replaceOrAppend (QAnyStringView name, QAnyStringView newValue) |
Q_NETWORK_EXPORT bool | replaceOrAppend (WellKnownHeader name, QAnyStringView newValue) |
Q_NETWORK_EXPORT bool | contains (QAnyStringView name) const |
Returns whether the headers contain header with name. | |
Q_NETWORK_EXPORT bool | contains (WellKnownHeader name) const |
Q_NETWORK_EXPORT void | clear () |
Clears all header entries. | |
Q_NETWORK_EXPORT void | removeAll (QAnyStringView name) |
Removes the header name. | |
Q_NETWORK_EXPORT void | removeAll (WellKnownHeader name) |
Q_NETWORK_EXPORT void | removeAt (qsizetype i) |
Removes the header at index i. | |
Q_NETWORK_EXPORT QByteArrayView | value (QAnyStringView name, QByteArrayView defaultValue={}) const noexcept |
Returns the value of the (first) header name, or defaultValue if it doesn't exist. | |
Q_NETWORK_EXPORT QByteArrayView | value (WellKnownHeader name, QByteArrayView defaultValue={}) const noexcept |
Q_NETWORK_EXPORT QList< QByteArray > | values (QAnyStringView name) const |
Returns the values of header name in a list. | |
Q_NETWORK_EXPORT QList< QByteArray > | values (WellKnownHeader name) const |
Q_NETWORK_EXPORT QByteArrayView | valueAt (qsizetype i) const noexcept |
Returns the header value at index i. | |
Q_NETWORK_EXPORT QLatin1StringView | nameAt (qsizetype i) const noexcept |
Returns the header name at index i. | |
Q_NETWORK_EXPORT QByteArray | combinedValue (QAnyStringView name) const |
Returns the values of header name in a comma-combined string. | |
Q_NETWORK_EXPORT QByteArray | combinedValue (WellKnownHeader name) const |
Q_NETWORK_EXPORT qsizetype | size () const noexcept |
Returns the number of header entries. | |
Q_NETWORK_EXPORT void | reserve (qsizetype size) |
Attempts to allocate memory for at least size header entries. | |
bool | isEmpty () const noexcept |
Returns true if the headers have size 0; otherwise returns false . | |
Q_NETWORK_EXPORT QList< std::pair< QByteArray, QByteArray > > | toListOfPairs () const |
Returns the header entries as a list of (name, value) pairs. | |
Q_NETWORK_EXPORT QMultiMap< QByteArray, QByteArray > | toMultiMap () const |
Returns the header entries as a map from name to value(s). | |
Q_NETWORK_EXPORT QMultiHash< QByteArray, QByteArray > | toMultiHash () const |
Returns the header entries as a hash from name to value(s). | |
Static Public Member Functions | |
static Q_NETWORK_EXPORT QByteArrayView | wellKnownHeaderName (WellKnownHeader name) noexcept |
Returns a header name corresponding to the provided name as a view. | |
static Q_NETWORK_EXPORT QHttpHeaders | fromListOfPairs (const QList< std::pair< QByteArray, QByteArray > > &headers) |
Creates a new QHttpHeaders object that is populated with headers. | |
static Q_NETWORK_EXPORT QHttpHeaders | fromMultiMap (const QMultiMap< QByteArray, QByteArray > &headers) |
Creates a new QHttpHeaders object that is populated with headers. | |
static Q_NETWORK_EXPORT QHttpHeaders | fromMultiHash (const QMultiHash< QByteArray, QByteArray > &headers) |
Creates a new QHttpHeaders object that is populated with headers. | |
Friends | |
Q_NETWORK_EXPORT QDebug | operator<< (QDebug debug, const QHttpHeaders &headers) |
Writes headers into debug stream. | |
Definition at line 18 of file qhttpheaders.h.
|
strong |
List of well known headers as per \l {https://www.iana.org/assignments/http-fields}{IANA registry}.
\value AIM \value Accept \value AcceptAdditions \value AcceptCH \value AcceptDatetime \value AcceptEncoding \value AcceptFeatures \value AcceptLanguage \value AcceptPatch \value AcceptPost \value AcceptRanges \value AcceptSignature \value AccessControlAllowCredentials \value AccessControlAllowHeaders \value AccessControlAllowMethods \value AccessControlAllowOrigin \value AccessControlExposeHeaders \value AccessControlMaxAge \value AccessControlRequestHeaders \value AccessControlRequestMethod \value Age \value Allow \value ALPN \value AltSvc \value AltUsed \value Alternates \value ApplyToRedirectRef \value AuthenticationControl \value AuthenticationInfo \value Authorization \value CacheControl \value CacheStatus \value CalManagedID \value CalDAVTimezones \value CapsuleProtocol \value CDNCacheControl \value CDNLoop \value CertNotAfter \value CertNotBefore \value ClearSiteData \value ClientCert \value ClientCertChain \value Close \value Connection \value ContentDigest \value ContentDisposition \value ContentEncoding \value ContentID \value ContentLanguage \value ContentLength \value ContentLocation \value ContentRange \value ContentSecurityPolicy \value ContentSecurityPolicyReportOnly \value ContentType \value Cookie \value CrossOriginEmbedderPolicy \value CrossOriginEmbedderPolicyReportOnly \value CrossOriginOpenerPolicy \value CrossOriginOpenerPolicyReportOnly \value CrossOriginResourcePolicy \value DASL \value Date \value DAV \value DeltaBase \value Depth \value Destination \value DifferentialID \value DPoP \value DPoPNonce \value EarlyData \value ETag \value Expect \value ExpectCT \value Expires \value Forwarded \value From \value Hobareg \value Host \value If \value IfMatch \value IfModifiedSince \value IfNoneMatch \value IfRange \value IfScheduleTagMatch \value IfUnmodifiedSince \value IM \value IncludeReferredTokenBindingID \value KeepAlive \value Label \value LastEventID \value LastModified \value Link \value Location \value LockToken \value MaxForwards \value MementoDatetime \value Meter \value MIMEVersion \value Negotiate \value NEL \value ODataEntityId \value ODataIsolation \value ODataMaxVersion \value ODataVersion \value OptionalWWWAuthenticate \value OrderingType \value Origin \value OriginAgentCluster \value OSCORE \value OSLCCoreVersion \value Overwrite \value PingFrom \value PingTo \value Position \value Prefer \value PreferenceApplied \value Priority \value ProxyAuthenticate \value ProxyAuthenticationInfo \value ProxyAuthorization \value ProxyStatus \value PublicKeyPins \value PublicKeyPinsReportOnly \value Range \value RedirectRef \value Referer \value Refresh \value ReplayNonce \value ReprDigest \value RetryAfter \value ScheduleReply \value ScheduleTag \value SecPurpose \value SecTokenBinding \value SecWebSocketAccept \value SecWebSocketExtensions \value SecWebSocketKey \value SecWebSocketProtocol \value SecWebSocketVersion \value Server \value ServerTiming \value SetCookie \value Signature \value SignatureInput \value SLUG \value SoapAction \value StatusURI \value StrictTransportSecurity \value Sunset \value SurrogateCapability \value SurrogateControl \value TCN \value TE \value Timeout \value Topic \value Traceparent \value Tracestate \value Trailer \value TransferEncoding \value TTL \value Upgrade \value Urgency \value UserAgent \value VariantVary \value Vary \value Via \value WantContentDigest \value WantReprDigest \value WWWAuthenticate \value XContentTypeOptions \value XFrameOptions \value AcceptCharset \value CPEPInfo \value Pragma \value ProtocolInfo \value ProtocolQuery
Definition at line 22 of file qhttpheaders.h.
|
noexcept |
Creates a new QHttpHeaders object.
Definition at line 876 of file qhttpheaders.cpp.
|
default |
Disposes of the headers object.
|
default |
Creates a copy of other.
|
defaultnoexcept |
Move-constructs the object from other, which will be left \l{isEmpty()}{empty}.
bool QHttpHeaders::append | ( | QAnyStringView | name, |
QAnyStringView | value ) |
Appends a header entry with name and value and returns true
if successful.
Definition at line 1147 of file qhttpheaders.cpp.
References d, isValidHttpHeaderNameField(), isValidHttpHeaderValueField(), and normalizedValue().
Referenced by QHttpHeaderParser::appendHeaderField(), QNetworkAccessManager::createRequest(), QRestAccessManagerPrivate::executeRequest(), QNetworkHeadersPrivate::fromRawToHttp(), setFromRawHeader(), and QHttpHeaderParser::setHeaderField().
bool QHttpHeaders::append | ( | WellKnownHeader | name, |
QAnyStringView | value ) |
Definition at line 1160 of file qhttpheaders.cpp.
References d, isValidHttpHeaderValueField(), and normalizedValue().
void QHttpHeaders::clear | ( | ) |
Clears all header entries.
Definition at line 1543 of file qhttpheaders.cpp.
References d.
Referenced by QHttpHeaderParser::clear(), QNetworkRequestFactory::clearCommonHeaders(), QHttpHeaderParser::clearHeaders(), and QNetworkHeadersPrivate::clearHeaders().
QByteArray QHttpHeaders::combinedValue | ( | QAnyStringView | name | ) | const |
Returns the values of header name in a comma-combined string.
Returns a null
QByteArray if the header with name doesn't exist.
Definition at line 1432 of file qhttpheaders.cpp.
References d.
Referenced by QNetworkHeadersPrivate::rawHeader().
QByteArray QHttpHeaders::combinedValue | ( | WellKnownHeader | name | ) | const |
Definition at line 1445 of file qhttpheaders.cpp.
References d.
bool QHttpHeaders::contains | ( | QAnyStringView | name | ) | const |
Returns whether the headers contain header with name.
Definition at line 1283 of file qhttpheaders.cpp.
References d, and headerNameMatches().
Referenced by QNetworkProxy::hasRawHeader(), QNetworkRequest::hasRawHeader(), QNetworkReplyWasmImplPrivate::headersReceived(), and QNetworkReplyHttpImplPrivate::replyDownloadMetaData().
bool QHttpHeaders::contains | ( | WellKnownHeader | name | ) | const |
Definition at line 1294 of file qhttpheaders.cpp.
References d, and headerNameMatches().
|
static |
Creates a new QHttpHeaders object that is populated with headers.
Definition at line 886 of file qhttpheaders.cpp.
References header(), and reserve().
|
static |
Creates a new QHttpHeaders object that is populated with headers.
Definition at line 916 of file qhttpheaders.cpp.
References reserve().
|
static |
Creates a new QHttpHeaders object that is populated with headers.
Definition at line 901 of file qhttpheaders.cpp.
References reserve().
bool QHttpHeaders::insert | ( | qsizetype | i, |
QAnyStringView | name, | ||
QAnyStringView | value ) |
Inserts a header entry at index i, with name and value.
The index must be valid (see \l size()). Returns whether the insert succeeded.
Definition at line 1178 of file qhttpheaders.cpp.
References d, i, isValidHttpHeaderNameField(), isValidHttpHeaderValueField(), and normalizedValue().
Referenced by QHttpHeaderParser::prependHeaderField().
bool QHttpHeaders::insert | ( | qsizetype | i, |
WellKnownHeader | name, | ||
QAnyStringView | value ) |
Definition at line 1192 of file qhttpheaders.cpp.
References d, i, isValidHttpHeaderValueField(), and normalizedValue().
|
inlinenoexcept |
Returns true
if the headers have size 0; otherwise returns false
.
Definition at line 248 of file qhttpheaders.h.
Referenced by QNetworkRequestFactory::clearCommonHeaders(), QNetworkHeadersPrivate::fromHttpToRaw(), QHttpHeaderParser::parseHeaders(), QNetworkHeadersPrivate::rawHeadersKeys(), and QCacheItem::read().
|
noexcept |
Returns the header name at index i.
The index i must be valid (see \l size()).
Header names are case-insensitive, and the returned names are lower-cased.
Definition at line 1414 of file qhttpheaders.cpp.
References QLatin1StringView::at(), d, and i.
Referenced by QNetworkReplyHttpImplPrivate::fetchCacheMetaData(), QNetworkHeadersPrivate::fromHttpToRaw(), QHttpNetworkRequestPrivate::header(), QNetworkHeadersPrivate::rawHeader(), and QNetworkHeadersPrivate::rawHeadersKeys().
|
default |
Assigns the contents of other and returns a reference to this object.
Move-assigns other and returns a reference to this object.
other will be left \l{isEmpty()}{empty}.
void QHttpHeaders::removeAll | ( | QAnyStringView | name | ) |
Removes the header name.
Definition at line 1307 of file qhttpheaders.cpp.
References d, and QHttpHeadersPrivate::removeAll().
Referenced by QHttpHeaderParser::removeHeaderField(), QNetworkHeadersPrivate::setCookedHeader(), and setFromRawHeader().
void QHttpHeaders::removeAll | ( | WellKnownHeader | name | ) |
Definition at line 1318 of file qhttpheaders.cpp.
References d, and QHttpHeadersPrivate::removeAll().
Removes the header at index i.
The index i must be valid (see \l size()).
Definition at line 1333 of file qhttpheaders.cpp.
bool QHttpHeaders::replace | ( | qsizetype | i, |
QAnyStringView | name, | ||
QAnyStringView | newValue ) |
Replaces the header entry at index i, with name and newValue.
The index must be valid (see \l size()). Returns whether the replace succeeded.
Definition at line 1212 of file qhttpheaders.cpp.
References d, i, isValidHttpHeaderNameField(), isValidHttpHeaderValueField(), and normalizedValue().
bool QHttpHeaders::replace | ( | qsizetype | i, |
WellKnownHeader | name, | ||
QAnyStringView | newValue ) |
Definition at line 1226 of file qhttpheaders.cpp.
References d, i, isValidHttpHeaderValueField(), and normalizedValue().
bool QHttpHeaders::replaceOrAppend | ( | QAnyStringView | name, |
QAnyStringView | newValue ) |
Definition at line 1266 of file qhttpheaders.cpp.
References append(), d, isValidHttpHeaderNameField(), isValidHttpHeaderValueField(), normalizedValue(), and QHttpHeadersPrivate::replaceOrAppend().
Referenced by QHttpNetworkConnectionChannel::ensureConnection(), QNetworkRequestFactoryPrivate::newRequest(), and QNetworkHeadersPrivate::setHeader().
bool QHttpHeaders::replaceOrAppend | ( | WellKnownHeader | name, |
QAnyStringView | newValue ) |
If QHttpHeaders already contains name, replaces its value with newValue and removes possible additional name entries. If name didn't exist, appends a new entry. Returns true
if successful.
This function is a convenience method for setting a unique name : newValue header. For most headers the relative order does not matter, which allows reusing an existing entry if one exists.
Definition at line 1251 of file qhttpheaders.cpp.
References append(), d, isValidHttpHeaderValueField(), normalizedValue(), and QHttpHeadersPrivate::replaceOrAppend().
Attempts to allocate memory for at least size header entries.
If you know in advance how how many header entries there will be, you may call this function to prevent reallocations and memory fragmentation.
Definition at line 1472 of file qhttpheaders.cpp.
References d.
Referenced by fromListOfPairs(), fromMultiHash(), fromMultiMap(), and QNetworkHeadersPrivate::fromRawToHttp().
|
noexcept |
Returns the number of header entries.
Definition at line 1458 of file qhttpheaders.cpp.
References d.
Referenced by QNetworkHeadersPrivate::fromHttpToRaw(), QHttpNetworkRequestPrivate::header(), QNetworkReplyWasmImplPrivate::headersReceived(), QNetworkHeadersPrivate::rawHeader(), and QNetworkHeadersPrivate::rawHeadersKeys().
|
inlinenoexcept |
Swaps this QHttpHeaders with other.
This function is very fast and never fails.
Definition at line 212 of file qhttpheaders.h.
References d, other(), and swap().
Referenced by swap().
QList< std::pair< QByteArray, QByteArray > > QHttpHeaders::toListOfPairs | ( | ) | const |
Returns the header entries as a list of (name, value) pairs.
Header names are case-insensitive, and the returned names are lower-cased.
Definition at line 1498 of file qhttpheaders.cpp.
References QList< T >::append(), d, list, and QList< T >::reserve().
QMultiHash< QByteArray, QByteArray > QHttpHeaders::toMultiHash | ( | ) | const |
QMultiMap< QByteArray, QByteArray > QHttpHeaders::toMultiMap | ( | ) | const |
Returns the header entries as a map from name to value(s).
Header names are case-insensitive, and the returned names are lower-cased.
Definition at line 1513 of file qhttpheaders.cpp.
References d, QMap< Key, T >::insert(), and map.
|
noexcept |
Returns the value of the (first) header name, or defaultValue if it doesn't exist.
Definition at line 1346 of file qhttpheaders.cpp.
References d.
Referenced by QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(), QCacheItem::canCompress(), QRestReplyPrivate::contentCharset(), QHttpHeaderParser::firstHeaderField(), QNetworkReplyHttpImplPrivate::postRequest(), QNetworkDiskCache::prepare(), QNetworkReplyHttpImplPrivate::replyDownloadMetaData(), and QNetworkHeadersPrivate::setCookedHeader().
|
noexcept |
Definition at line 1357 of file qhttpheaders.cpp.
References d.
|
noexcept |
Returns the header value at index i.
The index i must be valid (see \l size()).
Definition at line 1400 of file qhttpheaders.cpp.
Referenced by QNetworkHeadersPrivate::fromHttpToRaw(), QHttpNetworkRequestPrivate::header(), and QNetworkHeadersPrivate::rawHeader().
QList< QByteArray > QHttpHeaders::values | ( | QAnyStringView | name | ) | const |
Returns the values of header name in a list.
Returns an empty list if header with name doesn't exist.
Definition at line 1371 of file qhttpheaders.cpp.
References d.
Referenced by QHttpHeaderParser::headerFieldValues(), QHstsHeaderParser::parse(), QAuthenticatorPrivate::parseHttpResponse(), and QHttpNetworkConnectionPrivate::parseRedirectResponse().
QList< QByteArray > QHttpHeaders::values | ( | WellKnownHeader | name | ) | const |
Definition at line 1384 of file qhttpheaders.cpp.
References d.
|
staticnoexcept |
Returns a header name corresponding to the provided name as a view.
Definition at line 1489 of file qhttpheaders.cpp.
References headerNames, and qToUnderlying().
Referenced by QNetworkHeadersPrivate::fromHttpToRaw(), QNetworkHeadersPrivate::fromRawToHttp(), isSetCookie(), QNetworkHeadersPrivate::rawHeader(), and QNetworkHeadersPrivate::setCookedHeader().
|
friend |
Writes headers into debug stream.
Definition at line 972 of file qhttpheaders.cpp.