QHttpHeaders is a class for holding HTTP headers. 更多...
头: | #include <QHttpHeaders> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network) |
qmake: | QT += network |
Since: | Qt 6.7 |
enum class | 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 ) |
The class is an interface type for Qt networking APIs that use or consume such headers.
An HTTP header consists of name and value . When setting these, QHttpHeaders validates name and value to only contain characters allowed by the HTTP RFCs. For detailed information see RFC 9110 Chapters 5.1 and 5.5 .
In all, this means:
名称
must consist of visible ASCII characters, and must not be empty
值
may consist of arbitrary bytes, as long as header and use case specific encoding rules are adhered to.
值
may be empty
The setters of this class automatically remove any leading or trailing whitespaces from value , as they must be ignored during the value processing.
Most HTTP header values can be combined with a single comma
','
plus an optional whitespace, and the semantic meaning is preserved. As an example, these two should be semantically similar:
// Values as separate header entries myheadername: myheadervalue1 myheadername: myheadervalue2 // Combined value myheadername: myheadervalue1, myheadervalue2
However, there is a notable exception to this rule: Set-Cookie . Due to this and the possibility of custom use cases, QHttpHeaders does not automatically combine the values.
Most QHttpHeaders functions provide both QHttpHeaders::WellKnownHeader and QAnyStringView overloads. From a memory-usage and computation point of view it is recommended to use the QHttpHeaders::WellKnownHeader overloads.
List of well known headers as per IANA registry .
常量 | 值 |
---|---|
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
()
Creates a new QHttpHeaders object.
创建副本为 other .
[noexcept]
QHttpHeaders::
QHttpHeaders
(
QHttpHeaders
&&
other
)
Move-constructs the object from other , which will be left empty .
[noexcept]
QHttpHeaders::
~QHttpHeaders
()
Disposes of the headers object.
Appends a header entry with
name
and
value
并返回
true
若成功。
另请参阅 append (QHttpHeaders::WellKnownHeader, QAnyStringView) and Allowed field name and value characters .
此函数重载 append (QAnyStringView, QAnyStringView).
Clears all header entries.
另请参阅 size ().
Returns the values of header
name
in a comma-combined string. Returns a
null
QByteArray
if the header with
name
doesn't exist.
注意: Accessing the value(s) of 'Set-Cookie' header this way may not work as intended. It is a notable exception in the HTTP RFC in that its values cannot be combined this way. Prefer values () 代替。
另请参阅 values (QAnyStringView).
此函数重载 combinedValue (QAnyStringView).
Returns whether the headers contain header with name .
另请参阅 contains (QHttpHeaders::WellKnownHeader).
This function overloads has(QAnyStringView).
[static]
QHttpHeaders
QHttpHeaders::
fromListOfPairs
(const
QList
<
std::pair
<
QByteArray
,
QByteArray
>> &
headers
)
创建新的 QHttpHeaders object that is populated with headers .
另请参阅 Allowed field name and value characters .
[static]
QHttpHeaders
QHttpHeaders::
fromMultiHash
(const
QMultiHash
<
QByteArray
,
QByteArray
> &
headers
)
创建新的 QHttpHeaders object that is populated with headers .
另请参阅 Allowed field name and value characters .
[static]
QHttpHeaders
QHttpHeaders::
fromMultiMap
(const
QMultiMap
<
QByteArray
,
QByteArray
> &
headers
)
创建新的 QHttpHeaders object that is populated with headers .
另请参阅 Allowed field name and value characters .
Inserts a header entry at index i ,采用 name and value . The index must be valid (see size ()). Returns whether the insert succeeded.
另请参阅 append (), insert (qsizetype, QHttpHeaders::WellKnownHeader, QAnyStringView), size (),和 Allowed field name and value characters .
此函数重载 insert (qsizetype, QAnyStringView, QAnyStringView).
[noexcept]
bool
QHttpHeaders::
isEmpty
() const
返回
true
if the headers have size 0; otherwise returns
false
.
另请参阅 size ().
[noexcept]
QLatin1StringView
QHttpHeaders::
nameAt
(
qsizetype
i
) const
Returns the header name at index i . The index i must be valid (see size ()).
Header names are case-insensitive, and the returned names are lower-cased.
Removes the header name .
另请参阅 removeAt () 和 removeAll (QHttpHeaders::WellKnownHeader).
此函数重载 removeAll (QAnyStringView).
Removes the header at index i . The index i must be valid (see size ()).
另请参阅 removeAll (QHttpHeaders::WellKnownHeader), removeAll (QAnyStringView), and size ().
Replaces the header entry at index i ,采用 name and newValue . The index must be valid (see size ()). Returns whether the replace succeeded.
另请参阅 append (), replace (qsizetype, QHttpHeaders::WellKnownHeader, QAnyStringView), size (),和 Allowed field name and value characters .
此函数重载 replace (qsizetype, QAnyStringView, QAnyStringView).
试图分配内存为至少 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.
[noexcept]
qsizetype
QHttpHeaders::
size
() const
Returns the number of header entries.
[noexcept]
void
QHttpHeaders::
swap
(
QHttpHeaders
&
other
)
交换此 QHttpHeaders with other 。此函数非常快且从不失败。
Returns the header entries as a list of (name, value) pairs. Header names are case-insensitive, and the returned names are lower-cased.
Returns the header entries as a hash from name to value(s). Header names are case-insensitive, and the returned names are lower-cased.
Returns the header entries as a map from name to value(s). Header names are case-insensitive, and the returned names are lower-cased.
[noexcept]
QByteArrayView
QHttpHeaders::
value
(
QAnyStringView
name
,
QByteArrayView
defaultValue
= {}) const
Returns the value of the (first) header name ,或 defaultValue if it doesn't exist.
另请参阅 value (QHttpHeaders::WellKnownHeader, QByteArrayView).
[noexcept]
QByteArrayView
QHttpHeaders::
value
(
QHttpHeaders::WellKnownHeader
name
,
QByteArrayView
defaultValue
= {}) const
此函数重载 value (QAnyStringView, QByteArrayView).
[noexcept]
QByteArrayView
QHttpHeaders::
valueAt
(
qsizetype
i
) const
Returns the header value at index i . The index i must be valid (see size ()).
另请参阅 size (), value (), values (), combinedValue (),和 nameAt ().
Returns the values of header name in a list. Returns an empty list if header with name doesn't exist.
另请参阅 values (QHttpHeaders::WellKnownHeader).
此函数重载 values (QAnyStringView).
[static noexcept]
QByteArrayView
QHttpHeaders::
wellKnownHeaderName
(
QHttpHeaders::WellKnownHeader
name
)
Returns a header name corresponding to the provided name as a view.
Assigns the contents of other and returns a reference to this object.
[noexcept]
QHttpHeaders
&QHttpHeaders::
operator=
(
QHttpHeaders
&&
other
)
移动赋值 other and returns a reference to this object.
other will be left empty .
写入 headers into debug stream.