QHttpHeaders 类
QHttpHeaders 是一个用于存储 HTTP 头的类。 更多...
头 | #include <QHttpHeaders> |
CMake | find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network) |
qmake | QT += network |
自从 | Qt 6.7 |
公共类型
枚举类 | WellKnownHeader { AIM, Accept, AcceptAdditions, AcceptCH, AcceptDatetime, …, ProtocolQuery } |
公共函数
QHttpHeaders() | |
QHttpHeaders(const QHttpHeaders &other) | |
QHttpHeaders(QHttpHeaders &&other) | |
~QHttpHeaders() | |
bool | append(QAnyStringView name, QAnyStringView value) |
bool | append(QHttpHeaders::WellKnownHeader name, QAnyStringView value) |
void | clear() |
QByteArray | combinedValue(QAnyStringView name) const |
QByteArray | combinedValue(QHttpHeaders::WellKnownHeader name) const |
bool | contains(QAnyStringView name) const |
bool | contains(QHttpHeaders::WellKnownHeader name) const |
bool | insert(qsizetype i, QAnyStringView name, QAnyStringView value) |
bool | insert(qsizetype i, QHttpHeaders::WellKnownHeader name, QAnyStringView value) |
bool | isEmpty() const |
QLatin1StringView | nameAt(qsizetype i) const |
void | removeAll(QAnyStringView name) |
void | removeAll(QHttpHeaders::WellKnownHeader name) |
void | removeAt(qsizetype i) |
bool | replace(qsizetype i, QAnyStringView name, QAnyStringView newValue) |
bool | replace(qsizetype i, QHttpHeaders::WellKnownHeader name, QAnyStringView newValue) |
void | reserve(qsizetype size) |
qsizetype | size() const |
void | swap(QHttpHeaders &other) |
QList<std::pair<QByteArray, QByteArray>> | toListOfPairs() const |
QMultiHash<QByteArray, QByteArray> | toMultiHash() const |
QMultiMap<QByteArray, QByteArray> | toMultiMap() const |
QByteArrayView | value(QAnyStringView name, QByteArrayView defaultValue = {}) const |
QByteArrayView | value(QHttpHeaders::WellKnownHeader name, QByteArrayView defaultValue = {}) const |
QByteArrayView | valueAt(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) |
静态公共成员
QHttpHeaders | fromListOfPairs(const QList<std::pair<QByteArray, QByteArray>> &headers) |
QHttpHeaders | fromMultiHash(const QMultiHash<QByteArray, QByteArray> &headers) |
QHttpHeaders | fromMultiMap(const QMultiMap<QByteArray, QByteArray> &headers) |
QByteArrayView | wellKnownHeaderName(QHttpHeaders::WellKnownHeader name) |
相关非成员
QDebug | operator<<(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::WellKnownHeader和QAnyStringView的重载。从内存使用和计算的角度来看,建议使用QHttpHeaders::WellKnownHeader的重载。
成员类型文档
枚举类 QHttpHeaders::WellKnownHeader
IANA注册中的已知头列表。
常量 | 值 |
---|---|
QHttpHeaders::WellKnownHeader::AIM | 0 |
QHttpHeaders::WellKnownHeader::Accept | 1 |
QHttpHeaders::WellKnownHeader::AcceptAdditions | 2 |
QHttpHeaders::WellKnownHeader::AcceptCH | 3 |
QHttpHeaders::WellKnownHeader::AcceptDatetime | 4 |
QHttpHeaders::WellKnownHeader::AcceptEncoding | 5 |
QHttpHeaders::WellKnownHeader::AcceptFeatures | 6 |
QHttpHeaders::WellKnownHeader::AcceptLanguage | 7 |
QHttpHeaders::WellKnownHeader::AcceptPatch | 8 |
QHttpHeaders::WellKnownHeader::AcceptPost | 9 |
QHttpHeaders::WellKnownHeader::AcceptRanges | 10 |
QHttpHeaders::WellKnownHeader::AcceptSignature | 11 |
QHttpHeaders::WellKnownHeader::AccessControlAllowCredentials | 12 |
QHttpHeaders::WellKnownHeader::AccessControlAllowHeaders | 13 |
QHttpHeaders::WellKnownHeader::AccessControlAllowMethods | 14 |
QHttpHeaders::WellKnownHeader::AccessControlAllowOrigin | 15 |
QHttpHeaders::WellKnownHeader::AccessControlExposeHeaders | 16 |
QHttpHeaders::WellKnownHeader::AccessControlMaxAge | 17 |
QHttpHeaders::WellKnownHeader::AccessControlRequestHeaders | 18 |
QHttpHeaders::WellKnownHeader::AccessControlRequestMethod | 19 |
QHttpHeaders::WellKnownHeader::Age | 20 |
QHttpHeaders::WellKnownHeader::Allow | 21 |
QHttpHeaders::WellKnownHeader::ALPN | 22 |
QHttpHeaders::WellKnownHeader::AltSvc | 23 |
QHttpHeaders::WellKnownHeader::AltUsed | 24 |
QHttpHeaders::WellKnownHeader::Alternates | 25 |
QHttpHeaders::WellKnownHeader::ApplyToRedirectRef | 26 |
QHttpHeaders::WellKnownHeader::AuthenticationControl | 27 |
QHttpHeaders::WellKnownHeader::AuthenticationInfo | 28 |
QHttpHeaders::WellKnownHeader::Authorization | 29 |
QHttpHeaders::WellKnownHeader::CacheControl | 30 |
QHttpHeaders::WellKnownHeader::CacheStatus | 31 |
QHttpHeaders::WellKnownHeader::CalManagedID | 32 |
QHttpHeaders::WellKnownHeader::CalDAVTimezones | 33 |
QHttpHeaders::WellKnownHeader::CapsuleProtocol | 34 |
QHttpHeaders::WellKnownHeader::CDNCacheControl | 35 |
QHttpHeaders::WellKnownHeader::CDNLoop | 36 |
QHttpHeaders::WellKnownHeader::CertNotAfter | 37 |
QHttpHeaders::WellKnownHeader::CertNotBefore | 38 |
QHttpHeaders::WellKnownHeader::ClearSiteData | 39 |
QHttpHeaders::WellKnownHeader::ClientCert | 40 |
QHttpHeaders::WellKnownHeader::ClientCertChain | 41 |
QHttpHeaders::WellKnownHeader::Close | 42 |
QHttpHeaders::WellKnownHeader::Connection | 43 |
QHttpHeaders::WellKnownHeader::ContentDigest | 44 |
QHttpHeaders::WellKnownHeader::ContentDisposition | 45 |
QHttpHeaders::WellKnownHeader::ContentEncoding | 46 |
QHttpHeaders::WellKnownHeader::ContentID | 47 |
QHttpHeaders::WellKnownHeader::ContentLanguage | 48 |
QHttpHeaders::WellKnownHeader::ContentLength | 49 |
QHttpHeaders::WellKnownHeader::ContentLocation | 50 |
QHttpHeaders::WellKnownHeader::ContentRange | 51 |
QHttpHeaders::WellKnownHeader::ContentSecurityPolicy | 52 |
QHttpHeaders::WellKnownHeader::ContentSecurityPolicyReportOnly | 53 |
QHttpHeaders::WellKnownHeader::ContentType | 54 |
QHttpHeaders::WellKnownHeader::Cookie | 55 |
QHttpHeaders::WellKnownHeader::CrossOriginEmbedderPolicy | 56 |
QHttpHeaders::WellKnownHeader::CrossOriginEmbedderPolicyReportOnly | 57 |
QHttpHeaders::WellKnownHeader::CrossOriginOpenerPolicy | 58 |
QHttpHeaders::WellKnownHeader::CrossOriginOpenerPolicyReportOnly | 59 |
QHttpHeaders::WellKnownHeader::CrossOriginResourcePolicy | 60 |
QHttpHeaders::WellKnownHeader::DASL | 61 |
QHttpHeaders::WellKnownHeader::Date | 62 |
QHttpHeaders::WellKnownHeader::DAV | 63 |
QHttpHeaders::WellKnownHeader::DeltaBase | 64 |
QHttpHeaders::WellKnownHeader::Depth | 65 |
QHttpHeaders::WellKnownHeader::Destination | 66 |
QHttpHeaders::WellKnownHeader::DifferentialID | 67 |
QHttpHeaders::WellKnownHeader::DPoP | 68 |
QHttpHeaders::WellKnownHeader::DPoPNonce | 69 |
QHttpHeaders::WellKnownHeader::EarlyData | 70 |
QHttpHeaders::WellKnownHeader::ETag | 71 |
QHttpHeaders::WellKnownHeader::Expect | 72 |
QHttpHeaders::WellKnownHeader::ExpectCT | 73 |
QHttpHeaders::WellKnownHeader::Expires | 74 |
QHttpHeaders::WellKnownHeader::Forwarded | 75 |
QHttpHeaders::WellKnownHeader::From | 76 |
QHttpHeaders::WellKnownHeader::Hobareg | 77 |
QHttpHeaders::WellKnownHeader::Host | 78 |
QHttpHeaders::WellKnownHeader::If | 79 |
QHttpHeaders::WellKnownHeader::IfMatch | 80 |
QHttpHeaders::WellKnownHeader::IfModifiedSince | 81 |
QHttpHeaders::WellKnownHeader::IfNoneMatch | 82 |
QHttpHeaders::WellKnownHeader::IfRange | 83 |
QHttpHeaders::WellKnownHeader::IfScheduleTagMatch | 84 |
QHttpHeaders::WellKnownHeader::IfUnmodifiedSince | 85 |
QHttpHeaders::WellKnownHeader::IM | 86 |
QHttpHeaders::WellKnownHeader::IncludeReferredTokenBindingID | 87 |
QHttpHeaders::WellKnownHeader::KeepAlive | 88 |
QHttpHeaders::WellKnownHeader::Label | 89 |
QHttpHeaders::WellKnownHeader::LastEventID | 90 |
QHttpHeaders::WellKnownHeader::LastModified | 91 |
QHttpHeaders::WellKnownHeader::Link | 92 |
QHttpHeaders::WellKnownHeader::Location | 93 |
QHttpHeaders::WellKnownHeader::LockToken | 94 |
QHttpHeaders::WellKnownHeader::MaxForwards | 95 |
QHttpHeaders::WellKnownHeader::MementoDatetime | 96 |
QHttpHeaders::WellKnownHeader::Meter | 97 |
QHttpHeaders::WellKnownHeader::MIMEVersion | 98 |
QHttpHeaders::WellKnownHeader::Negotiate | 99 |
QHttpHeaders::WellKnownHeader::NEL | 100 |
QHttpHeaders::WellKnownHeader::ODataEntityId | 101 |
QHttpHeaders::WellKnownHeader::ODataIsolation | 102 |
QHttpHeaders::WellKnownHeader::ODataMaxVersion | 103 |
QHttpHeaders::WellKnownHeader::ODataVersion | 104 |
QHttpHeaders::WellKnownHeader::OptionalWWWAuthenticate | 105 |
QHttpHeaders::WellKnownHeader::OrderingType | 106 |
QHttpHeaders::WellKnownHeader::Origin | 107 |
QHttpHeaders::WellKnownHeader::OriginAgentCluster | 108 |
QHttpHeaders::WellKnownHeader::OSCORE | 109 |
QHttpHeaders::WellKnownHeader::OSLCCoreVersion | 110 |
QHttpHeaders::WellKnownHeader::Overwrite | 111 |
QHttpHeaders::WellKnownHeader::PingFrom | 112 |
QHttpHeaders::WellKnownHeader::PingTo | 113 |
QHttpHeaders::WellKnownHeader::Position | 114 |
QHttpHeaders::WellKnownHeader::Prefer | 115 |
QHttpHeaders::WellKnownHeader::PreferenceApplied | 116 |
QHttpHeaders::WellKnownHeader::Priority | 117 |
QHttpHeaders::WellKnownHeader::ProxyAuthenticate | 118 |
QHttpHeaders::WellKnownHeader::ProxyAuthenticationInfo | 119 |
QHttpHeaders::WellKnownHeader::ProxyAuthorization | 120 |
QHttpHeaders::WellKnownHeader::ProxyStatus | 121 |
QHttpHeaders::WellKnownHeader::PublicKeyPins | 122 |
QHttpHeaders::WellKnownHeader::PublicKeyPinsReportOnly | 123 |
QHttpHeaders::WellKnownHeader::Range | 124 |
QHttpHeaders::WellKnownHeader::RedirectRef | 125 |
QHttpHeaders::WellKnownHeader::Referer | 126 |
QHttpHeaders::WellKnownHeader::Refresh | 127 |
QHttpHeaders::WellKnownHeader::ReplayNonce | 128 |
QHttpHeaders::WellKnownHeader::ReprDigest | 129 |
QHttpHeaders::WellKnownHeader::RetryAfter | 130 |
QHttpHeaders::WellKnownHeader::ScheduleReply | 131 |
QHttpHeaders::WellKnownHeader::ScheduleTag | 132 |
QHttpHeaders::WellKnownHeader::SecPurpose | 133 |
QHttpHeaders::WellKnownHeader::SecTokenBinding | 134 |
QHttpHeaders::WellKnownHeader::SecWebSocketAccept | 135 |
QHttpHeaders::WellKnownHeader::SecWebSocketExtensions | 136 |
QHttpHeaders::WellKnownHeader::SecWebSocketKey | 137 |
QHttpHeaders::WellKnownHeader::SecWebSocketProtocol | 138 |
QHttpHeaders::WellKnownHeader::SecWebSocketVersion | 139 |
QHttpHeaders::WellKnownHeader::Server | 140 |
QHttpHeaders::WellKnownHeader::ServerTiming | 141 |
QHttpHeaders::WellKnownHeader::SetCookie | 142 |
QHttpHeaders::WellKnownHeader::Signature | 143 |
QHttpHeaders::WellKnownHeader::SignatureInput | 144 |
QHttpHeaders::WellKnownHeader::SLUG | 145 |
QHttpHeaders::WellKnownHeader::SoapAction | 146 |
QHttpHeaders::WellKnownHeader::StatusURI | 147 |
QHttpHeaders::WellKnownHeader::StrictTransportSecurity | 148 |
QHttpHeaders::WellKnownHeader::Sunset | 149 |
QHttpHeaders::WellKnownHeader::SurrogateCapability | 150 |
QHttpHeaders::WellKnownHeader::SurrogateControl | 151 |
QHttpHeaders::WellKnownHeader::TCN | 152 |
QHttpHeaders::WellKnownHeader::TE | 153 |
QHttpHeaders::WellKnownHeader::Timeout | 154 |
QHttpHeaders::WellKnownHeader::Topic | 155 |
QHttpHeaders::WellKnownHeader::Traceparent | 156 |
QHttpHeaders::WellKnownHeader::Tracestate | 157 |
QHttpHeaders::WellKnownHeader::Trailer | 158 |
QHttpHeaders::WellKnownHeader::TransferEncoding | 159 |
QHttpHeaders::WellKnownHeader::TTL | 160 |
QHttpHeaders::WellKnownHeader::Upgrade | 161 |
QHttpHeaders::WellKnownHeader::Urgency | 162 |
QHttpHeaders::WellKnownHeader::UserAgent | 163 |
QHttpHeaders::WellKnownHeader::VariantVary | 164 |
QHttpHeaders::WellKnownHeader::Vary | 165 |
QHttpHeaders::WellKnownHeader::Via | 166 |
QHttpHeaders::WellKnownHeader::WantContentDigest | 167 |
QHttpHeaders::WellKnownHeader::WantReprDigest | 168 |
QHttpHeaders::WellKnownHeader::WWWAuthenticate | 169 |
QHttpHeaders::WellKnownHeader::XContentTypeOptions | 170 |
QHttpHeaders::WellKnownHeader::XFrameOptions | 171 |
QHttpHeaders::WellKnownHeader::AcceptCharset | 172 |
QHttpHeaders::WellKnownHeader::CPEPInfo | 173 |
QHttpHeaders::WellKnownHeader::Pragma | 174 |
QHttpHeaders::WellKnownHeader::ProtocolInfo | 175 |
QHttpHeaders::WellKnownHeader::ProtocolQuery | 176 |
成员函数文档
[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)
放置带有 name 和 value 的头部条目,如果成功则返回 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( )
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将被置为空。
© 2024 The Qt Company Ltd. 本文档中包含的贡献归其各自所有者所有。本提供的文档遵照GNU自由文档许可证版本1.3进行许可,该许可证由自由软件基金会发布。Qt及其相关标志是The Qt Company Ltd.在芬兰及/或其他国家的商标。所有其他商标均为其各自所有者的财产。