QHttpHeaders 类

QHttpHeaders 是一个用于存储 HTTP 头的类。 更多...

#include <QHttpHeaders>
CMakefind_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
qmakeQT += network
自从Qt 6.7

公共类型

枚举类WellKnownHeader { AIM, Accept, AcceptAdditions, AcceptCH, AcceptDatetime, …, ProtocolQuery }

公共函数

QHttpHeaders()
QHttpHeaders(const QHttpHeaders &other)
QHttpHeaders(QHttpHeaders &&other)
~QHttpHeaders()
boolappend(QAnyStringView name, QAnyStringView value)
boolappend(QHttpHeaders::WellKnownHeader name, QAnyStringView value)
voidclear()
QByteArraycombinedValue(QAnyStringView name) const
QByteArraycombinedValue(QHttpHeaders::WellKnownHeader name) const
boolcontains(QAnyStringView name) const
boolcontains(QHttpHeaders::WellKnownHeader name) const
boolinsert(qsizetype i, QAnyStringView name, QAnyStringView value)
boolinsert(qsizetype i, QHttpHeaders::WellKnownHeader name, QAnyStringView value)
boolisEmpty() const
QLatin1StringViewnameAt(qsizetype i) const
voidremoveAll(QAnyStringView name)
voidremoveAll(QHttpHeaders::WellKnownHeader name)
voidremoveAt(qsizetype i)
boolreplace(qsizetype i, QAnyStringView name, QAnyStringView newValue)
boolreplace(qsizetype i, QHttpHeaders::WellKnownHeader name, QAnyStringView newValue)
voidreserve(qsizetype size)
qsizetypesize() const
voidswap(QHttpHeaders &other)
QList<std::pair<QByteArray, QByteArray>>toListOfPairs() const
QMultiHash<QByteArray, QByteArray>toMultiHash() const
QMultiMap<QByteArray, QByteArray>toMultiMap() const
QByteArrayViewvalue(QAnyStringView name, QByteArrayView defaultValue = {}) const
QByteArrayViewvalue(QHttpHeaders::WellKnownHeader name, QByteArrayView defaultValue = {}) const
QByteArrayViewvalueAt(qsizetype i) const
QList<QByteArray>values(QAnyStringView name) const
QList<QByteArray>values(QHttpHeaders::WellKnownHeader name) const
QHttpHeaders &operator=(const QHttpHeaders &other)
QHttpHeaders &operator=(QHttpHeaders &&other)

静态公共成员

QHttpHeadersfromListOfPairs(const QList<std::pair<QByteArray, QByteArray>> &headers)
QHttpHeadersfromMultiHash(const QMultiHash<QByteArray, QByteArray> &headers)
QHttpHeadersfromMultiMap(const QMultiMap<QByteArray, QByteArray> &headers)
QByteArrayViewwellKnownHeaderName(QHttpHeaders::WellKnownHeader name)
QDebugoperator<<(QDebug debug, const QHttpHeaders &headers)

详细描述

此类是Qt网络API使用或消费此类头的接口类型。

允许的字段名和值字符

HTTP头由名称组成。设置这些值时,QHttpHeaders将验证名称是否只包含HTTP RFCs允许的字符。有关详细信息,请参阅RFC 9110第5.1节和第5.5节

总的来说这意味着

  • name必须由可见的ASCII字符组成,且不能为空
  • value可以由任意字节组成,只要遵循特定的头和用法编码规则。value可以为空

此类设置器会自动从value中移除任何前导或尾随空格,因为在value处理过程中应忽略这些空格。

合并值

大多数HTTP头值可以与单个逗号','和一个可选项的空白字符合并,并保留其语义意义。例如,这两个应该具有相似的语义

// Values as separate header entries
myheadername: myheadervalue1
myheadername: myheadervalue2
// Combined value
myheadername: myheadervalue1, myheadervalue2

然而,有一个显著的例外是规则:Set-Cookie。由于这一点以及可能的自定义用例,QHttpHeaders不会自动合并值。

性能

大多数QHttpHeaders函数都提供了QHttpHeaders::WellKnownHeaderQAnyStringView的重载。从内存使用和计算的角度来看,建议使用QHttpHeaders::WellKnownHeader的重载。

成员类型文档

枚举类 QHttpHeaders::WellKnownHeader

IANA注册中的已知头列表。

常量
QHttpHeaders::WellKnownHeader::AIM0
QHttpHeaders::WellKnownHeader::Accept1
QHttpHeaders::WellKnownHeader::AcceptAdditions2
QHttpHeaders::WellKnownHeader::AcceptCH3
QHttpHeaders::WellKnownHeader::AcceptDatetime4
QHttpHeaders::WellKnownHeader::AcceptEncoding5
QHttpHeaders::WellKnownHeader::AcceptFeatures6
QHttpHeaders::WellKnownHeader::AcceptLanguage7
QHttpHeaders::WellKnownHeader::AcceptPatch8
QHttpHeaders::WellKnownHeader::AcceptPost9
QHttpHeaders::WellKnownHeader::AcceptRanges10
QHttpHeaders::WellKnownHeader::AcceptSignature11
QHttpHeaders::WellKnownHeader::AccessControlAllowCredentials12
QHttpHeaders::WellKnownHeader::AccessControlAllowHeaders13
QHttpHeaders::WellKnownHeader::AccessControlAllowMethods14
QHttpHeaders::WellKnownHeader::AccessControlAllowOrigin15
QHttpHeaders::WellKnownHeader::AccessControlExposeHeaders16
QHttpHeaders::WellKnownHeader::AccessControlMaxAge17
QHttpHeaders::WellKnownHeader::AccessControlRequestHeaders18
QHttpHeaders::WellKnownHeader::AccessControlRequestMethod19
QHttpHeaders::WellKnownHeader::Age20
QHttpHeaders::WellKnownHeader::Allow21
QHttpHeaders::WellKnownHeader::ALPN22
QHttpHeaders::WellKnownHeader::AltSvc23
QHttpHeaders::WellKnownHeader::AltUsed24
QHttpHeaders::WellKnownHeader::Alternates25
QHttpHeaders::WellKnownHeader::ApplyToRedirectRef26
QHttpHeaders::WellKnownHeader::AuthenticationControl27
QHttpHeaders::WellKnownHeader::AuthenticationInfo28
QHttpHeaders::WellKnownHeader::Authorization29
QHttpHeaders::WellKnownHeader::CacheControl30
QHttpHeaders::WellKnownHeader::CacheStatus31
QHttpHeaders::WellKnownHeader::CalManagedID32
QHttpHeaders::WellKnownHeader::CalDAVTimezones33
QHttpHeaders::WellKnownHeader::CapsuleProtocol34
QHttpHeaders::WellKnownHeader::CDNCacheControl35
QHttpHeaders::WellKnownHeader::CDNLoop36
QHttpHeaders::WellKnownHeader::CertNotAfter37
QHttpHeaders::WellKnownHeader::CertNotBefore38
QHttpHeaders::WellKnownHeader::ClearSiteData39
QHttpHeaders::WellKnownHeader::ClientCert40
QHttpHeaders::WellKnownHeader::ClientCertChain41
QHttpHeaders::WellKnownHeader::Close42
QHttpHeaders::WellKnownHeader::Connection43
QHttpHeaders::WellKnownHeader::ContentDigest44
QHttpHeaders::WellKnownHeader::ContentDisposition45
QHttpHeaders::WellKnownHeader::ContentEncoding46
QHttpHeaders::WellKnownHeader::ContentID47
QHttpHeaders::WellKnownHeader::ContentLanguage48
QHttpHeaders::WellKnownHeader::ContentLength49
QHttpHeaders::WellKnownHeader::ContentLocation50
QHttpHeaders::WellKnownHeader::ContentRange51
QHttpHeaders::WellKnownHeader::ContentSecurityPolicy52
QHttpHeaders::WellKnownHeader::ContentSecurityPolicyReportOnly53
QHttpHeaders::WellKnownHeader::ContentType54
QHttpHeaders::WellKnownHeader::Cookie55
QHttpHeaders::WellKnownHeader::CrossOriginEmbedderPolicy56
QHttpHeaders::WellKnownHeader::CrossOriginEmbedderPolicyReportOnly57
QHttpHeaders::WellKnownHeader::CrossOriginOpenerPolicy58
QHttpHeaders::WellKnownHeader::CrossOriginOpenerPolicyReportOnly59
QHttpHeaders::WellKnownHeader::CrossOriginResourcePolicy60
QHttpHeaders::WellKnownHeader::DASL61
QHttpHeaders::WellKnownHeader::Date62
QHttpHeaders::WellKnownHeader::DAV63
QHttpHeaders::WellKnownHeader::DeltaBase64
QHttpHeaders::WellKnownHeader::Depth65
QHttpHeaders::WellKnownHeader::Destination66
QHttpHeaders::WellKnownHeader::DifferentialID67
QHttpHeaders::WellKnownHeader::DPoP68
QHttpHeaders::WellKnownHeader::DPoPNonce69
QHttpHeaders::WellKnownHeader::EarlyData70
QHttpHeaders::WellKnownHeader::ETag71
QHttpHeaders::WellKnownHeader::Expect72
QHttpHeaders::WellKnownHeader::ExpectCT73
QHttpHeaders::WellKnownHeader::Expires74
QHttpHeaders::WellKnownHeader::Forwarded75
QHttpHeaders::WellKnownHeader::From76
QHttpHeaders::WellKnownHeader::Hobareg77
QHttpHeaders::WellKnownHeader::Host78
QHttpHeaders::WellKnownHeader::If79
QHttpHeaders::WellKnownHeader::IfMatch80
QHttpHeaders::WellKnownHeader::IfModifiedSince81
QHttpHeaders::WellKnownHeader::IfNoneMatch82
QHttpHeaders::WellKnownHeader::IfRange83
QHttpHeaders::WellKnownHeader::IfScheduleTagMatch84
QHttpHeaders::WellKnownHeader::IfUnmodifiedSince85
QHttpHeaders::WellKnownHeader::IM86
QHttpHeaders::WellKnownHeader::IncludeReferredTokenBindingID87
QHttpHeaders::WellKnownHeader::KeepAlive88
QHttpHeaders::WellKnownHeader::Label89
QHttpHeaders::WellKnownHeader::LastEventID90
QHttpHeaders::WellKnownHeader::LastModified91
QHttpHeaders::WellKnownHeader::Link92
QHttpHeaders::WellKnownHeader::Location93
QHttpHeaders::WellKnownHeader::LockToken94
QHttpHeaders::WellKnownHeader::MaxForwards95
QHttpHeaders::WellKnownHeader::MementoDatetime96
QHttpHeaders::WellKnownHeader::Meter97
QHttpHeaders::WellKnownHeader::MIMEVersion98
QHttpHeaders::WellKnownHeader::Negotiate99
QHttpHeaders::WellKnownHeader::NEL100
QHttpHeaders::WellKnownHeader::ODataEntityId101
QHttpHeaders::WellKnownHeader::ODataIsolation102
QHttpHeaders::WellKnownHeader::ODataMaxVersion103
QHttpHeaders::WellKnownHeader::ODataVersion104
QHttpHeaders::WellKnownHeader::OptionalWWWAuthenticate105
QHttpHeaders::WellKnownHeader::OrderingType106
QHttpHeaders::WellKnownHeader::Origin107
QHttpHeaders::WellKnownHeader::OriginAgentCluster108
QHttpHeaders::WellKnownHeader::OSCORE109
QHttpHeaders::WellKnownHeader::OSLCCoreVersion110
QHttpHeaders::WellKnownHeader::Overwrite111
QHttpHeaders::WellKnownHeader::PingFrom112
QHttpHeaders::WellKnownHeader::PingTo113
QHttpHeaders::WellKnownHeader::Position114
QHttpHeaders::WellKnownHeader::Prefer115
QHttpHeaders::WellKnownHeader::PreferenceApplied116
QHttpHeaders::WellKnownHeader::Priority117
QHttpHeaders::WellKnownHeader::ProxyAuthenticate118
QHttpHeaders::WellKnownHeader::ProxyAuthenticationInfo119
QHttpHeaders::WellKnownHeader::ProxyAuthorization120
QHttpHeaders::WellKnownHeader::ProxyStatus121
QHttpHeaders::WellKnownHeader::PublicKeyPins122
QHttpHeaders::WellKnownHeader::PublicKeyPinsReportOnly123
QHttpHeaders::WellKnownHeader::Range124
QHttpHeaders::WellKnownHeader::RedirectRef125
QHttpHeaders::WellKnownHeader::Referer126
QHttpHeaders::WellKnownHeader::Refresh127
QHttpHeaders::WellKnownHeader::ReplayNonce128
QHttpHeaders::WellKnownHeader::ReprDigest129
QHttpHeaders::WellKnownHeader::RetryAfter130
QHttpHeaders::WellKnownHeader::ScheduleReply131
QHttpHeaders::WellKnownHeader::ScheduleTag132
QHttpHeaders::WellKnownHeader::SecPurpose133
QHttpHeaders::WellKnownHeader::SecTokenBinding134
QHttpHeaders::WellKnownHeader::SecWebSocketAccept135
QHttpHeaders::WellKnownHeader::SecWebSocketExtensions136
QHttpHeaders::WellKnownHeader::SecWebSocketKey137
QHttpHeaders::WellKnownHeader::SecWebSocketProtocol138
QHttpHeaders::WellKnownHeader::SecWebSocketVersion139
QHttpHeaders::WellKnownHeader::Server140
QHttpHeaders::WellKnownHeader::ServerTiming141
QHttpHeaders::WellKnownHeader::SetCookie142
QHttpHeaders::WellKnownHeader::Signature143
QHttpHeaders::WellKnownHeader::SignatureInput144
QHttpHeaders::WellKnownHeader::SLUG145
QHttpHeaders::WellKnownHeader::SoapAction146
QHttpHeaders::WellKnownHeader::StatusURI147
QHttpHeaders::WellKnownHeader::StrictTransportSecurity148
QHttpHeaders::WellKnownHeader::Sunset149
QHttpHeaders::WellKnownHeader::SurrogateCapability150
QHttpHeaders::WellKnownHeader::SurrogateControl151
QHttpHeaders::WellKnownHeader::TCN152
QHttpHeaders::WellKnownHeader::TE153
QHttpHeaders::WellKnownHeader::Timeout154
QHttpHeaders::WellKnownHeader::Topic155
QHttpHeaders::WellKnownHeader::Traceparent156
QHttpHeaders::WellKnownHeader::Tracestate157
QHttpHeaders::WellKnownHeader::Trailer158
QHttpHeaders::WellKnownHeader::TransferEncoding159
QHttpHeaders::WellKnownHeader::TTL160
QHttpHeaders::WellKnownHeader::Upgrade161
QHttpHeaders::WellKnownHeader::Urgency162
QHttpHeaders::WellKnownHeader::UserAgent163
QHttpHeaders::WellKnownHeader::VariantVary164
QHttpHeaders::WellKnownHeader::Vary165
QHttpHeaders::WellKnownHeader::Via166
QHttpHeaders::WellKnownHeader::WantContentDigest167
QHttpHeaders::WellKnownHeader::WantReprDigest168
QHttpHeaders::WellKnownHeader::WWWAuthenticate169
QHttpHeaders::WellKnownHeader::XContentTypeOptions170
QHttpHeaders::WellKnownHeader::XFrameOptions171
QHttpHeaders::WellKnownHeader::AcceptCharset172
QHttpHeaders::WellKnownHeader::CPEPInfo173
QHttpHeaders::WellKnownHeader::Pragma174
QHttpHeaders::WellKnownHeader::ProtocolInfo175
QHttpHeaders::WellKnownHeader::ProtocolQuery176

成员函数文档

[noexcept] QHttpHeaders::QHttpHeaders()

创建一个新的 QHttpHeaders 对象。

QHttpHeaders::QHttpHeaders(const QHttpHeaders &other)

创建局部对象的副本。

[noexcept] QHttpHeaders::QHttpHeaders(QHttpHeaders &&other)

other 重新构造对象,这将留下一个空对象。

[noexcept] QHttpHeaders::~QHttpHeaders()

处理头部对象。

bool QHttpHeaders::append(QAnyStringView name, QAnyStringView value)

放置带有 namevalue 的头部条目,如果成功则返回 true

另请参阅append(QHttpHeaders::WellKnownHeader, QAnyStringView) 和 允许的字段名和值字符

bool QHttpHeaders::append(QHttpHeaders::WellKnownHeader name, QAnyStringView value)

此函数在 append(QAnyStringView, QAnyStringView) 上进行了重载。

void QHttpHeaders::clear()

清除所有头部条目。

另请参阅size()。

QByteArray QHttpHeaders::combinedValue(QAnyStringView name) const

按逗号分隔字符串返回头部名称的值。如果不存在带有 name 的头部,则返回空的 QByteArray

注意:以这种方式访问‘Set-Cookie’头部值可能无法按预期工作。这是HTTP RFC中的一个显著例外,因为其值不能这样组合。请首选使用values()。

另请参阅:values(QAnyStringView)。

QByteArray QHttpHeaders::combinedValue(QHttpHeaders::WellKnownHeader 名称) const

此函数重载combinedValue(QAnyStringView)。

bool QHttpHeaders::contains(QAnyStringView 名称) const

返回头是否包含具有名称的头部。

另请参阅:contains(QHttpHeaders::WellKnownHeader)。

bool QHttpHeaders::contains(QHttpHeaders::WellKnownHeader 名称) const

此函数重载了has(QAnyStringView)。

[静态] QHttpHeaders QHttpHeaders::fromListOfPairs(const QList<std::pair<QByteArray, QByteArray>> &headers)

创建一个新的QHttpHeaders对象,并用headers填充。

另请参阅:允许的字段名称和值字符

[静态] QHttpHeaders QHttpHeaders::fromMultiHash(const QMultiHash<QByteArray, QByteArray> &headers)

创建一个新的QHttpHeaders对象,并用headers填充。

另请参阅:允许的字段名称和值字符

[静态] QHttpHeaders QHttpHeaders::fromMultiMap(const QMultiMap<QByteArray, QByteArray> &headers)

创建一个新的QHttpHeaders对象,并用headers填充。

另请参阅:允许的字段名称和值字符

bool QHttpHeaders::insert(qsizetype 索引, QAnyStringView 名称, QAnyStringView )

在索引索引处插入带有名称的头部条目。索引必须有效(请参阅size())。返回插入是否成功。

另请参阅:append()、insert(qsizetype, QHttpHeaders::WellKnownHeader, QAnyStringView),size()以及允许的字段名称和值字符

bool QHttpHeaders::insert(qsizetype 索引, QHttpHeaders::WellKnownHeader 名称, QAnyStringView )

此函数重载了insert(qsizetype, QAnyStringView, QAnyStringView)。

[noexcept] bool QHttpHeaders::isEmpty() const

当头部尺寸为0时返回true,否则返回false

另请参阅size()。

QHttpHeaders::nameAt( ) const

返回索引处的头部名称。索引必须有效(参见()).

头部名称不区分大小写,返回的名称均为小写。

另请参阅() 和 ().

void QHttpHeaders::removeAll( )

移除头部

另请参阅() 和 (QHttpHeaders::WellKnownHeader)。

void QHttpHeaders::removeAll( )

此函数重载(QAnyStringView)。

void QHttpHeaders::removeAt( )

移除索引处的头部。索引必须有效(参见()).

另请参阅(QHttpHeaders::WellKnownHeader), (QAnyStringView), 以及 ().

bool QHttpHeaders::replace( , , )

替换索引处的头部条目,带有。索引必须有效(参见()). 返回是否替换成功。

另请参阅(), (qsizetype, QHttpHeaders::WellKnownHeader, QAnyStringView), (), 以及 ().

bool QHttpHeaders::replace( , , )

此函数重载(qsizetype, QAnyStringView, QAnyStringView)。

void QHttpHeaders::reserve( )

尝试为至少个头部条目分配内存。

如果您事先知道将有多少个头部条目,您可以调用此函数,以防止重新分配和内存碎片。

QHttpHeaders::size() const

返回头部条目的数量。

void QHttpHeaders::swap( &)

将此 QHttpHeaders其他 交换。此函数执行非常快,且从不失败。

QList<std::pair<QByteArray, QByteArray>> QHttpHeaders::toListOfPairs() const

将报头条目作为(名称,值)对的列表返回。报头名称不区分大小写,并且返回的名称为小写。

QMultiHash<QByteArray, QByteArray> QHttpHeaders::toMultiHash() const

将报头条目作为从名称到值的哈希表返回。报头名称不区分大小写,并且返回的名称为小写。

QMultiMap<QByteArray, QByteArray> QHttpHeaders::toMultiMap() const

将报头条目作为从名称到值的映射表返回。报头名称不区分大小写,并且返回的名称为小写。

[noexcept] QByteArrayView QHttpHeaders::value(QAnyStringView name, QByteArrayView defaultValue = {}) const

返回(第一个)报头 name 的值,或不存在时返回 defaultValue

另请参阅 value(QHttpHeaders::WellKnownHeader, QByteArrayView).

[noexcept] QByteArrayView QHttpHeaders::value(QHttpHeaders::WellKnownHeader name, QByteArrayView defaultValue = {}) const

此函数重载了 value(QAnyStringView, QByteArrayView).

[noexcept] QByteArrayView QHttpHeaders::valueAt(qsizetype i) const

返回索引 i 处的报头值。索引 i 必须有效(参见 size())。

另请参阅 size(), value(), values(), combinedValue() 和 nameAt().

QList<QByteArray> QHttpHeaders::values(QAnyStringView name) const

以列表形式返回报头 name 的值。如果不存在具有 name 的报头,则返回空列表。

另请参阅 values(QHttpHeaders::WellKnownHeader).

QList<QByteArray> QHttpHeaders::values(QHttpHeaders::WellKnownHeader name) const

此函数重载了values(QAnyStringView)。

[静态 noexcept] QByteArrayView QHttpHeaders::wellKnownHeaderName(QHttpHeaders::WellKnownHeader name)

返回与提供的name相对应的头名字符串作为视图。

QHttpHeaders &QHttpHeaders::operator=(const QHttpHeaders &other)

other的内容赋值给当前对象,并返回对此对象的引用。

[noexcept] QHttpHeaders &QHttpHeaders::operator=(QHttpHeaders &&other)

移动赋值other并返回对此对象的引用。

other将被置为空。

相关非成员函数

QDebug operator<<(QDebug debug, const QHttpHeaders &headers)

headers写入debug流。

© 2024 The Qt Company Ltd. 本文档中包含的贡献归其各自所有者所有。本提供的文档遵照GNU自由文档许可证版本1.3进行许可,该许可证由自由软件基金会发布。Qt及其相关标志是The Qt Company Ltd.在芬兰及/或其他国家的商标。所有其他商标均为其各自所有者的财产。