class QHttpHeaders#

QHttpHeaders 是一个用于存储 HTTP 头部的类。 更多信息

自6.7版开始使用。

摘要#

方法#

静态函数#

注意

此文档可能包含从 C++ 自动翻译到 Python 的代码片段。我们始终欢迎对片段翻译的贡献。如果您发现翻译中有问题,也可以通过在 https:/bugreports.qt.io/projects/PYSIDE 上创建工单来让我们知道。

详细描述#

此类是 Qt 网络 API 的接口类型,用于或使用此类头部。

允许的字段名和值字符#

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

广泛地说,这意味着

  • name 必须由可见的 ASCII 字符组成,且不能为空

  • value 可以由任意字节组成,只要遵循头部和使用情况特定的编码规则。《code class="docutils literal notranslate">value 可以是空的

此外,value 在历史上可能包含开头或结尾的空白字符,在处理此类值时必须忽略这些空白字符。此类的设置器会自动删除此类空白字符。

值的组合#

大多数 HTTP 头部值可以通过单个逗号 ',' 进行组合,并且语义意义得到保留。例如,这两个应该是语义上相似的

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

然而,有一个值得注意的例外:Set-Cookie。由于这一点,以及由于可能的自定义使用情况,QHttpHeaders 不会自动组合值。

class WellKnownHeader#

根据 IANA 注册表 的已知头部列表。

常量

描述

QHttpHeaders.WellKnownHeader.AIM

QHttpHeaders.WellKnownHeader.Accept

QHttpHeaders.WellKnownHeader.AcceptAdditions

QHttpHeaders.WellKnownHeader.AcceptCH

QHttpHeaders.WellKnownHeader.AcceptDatetime

QHttpHeaders.WellKnownHeader.AcceptEncoding

QHttpHeaders.WellKnownHeader.AcceptFeatures

QHttpHeaders.WellKnownHeader.AcceptLanguage

QHttpHeaders.WellKnownHeader.AcceptPatch

QHttpHeaders.WellKnownHeader.AcceptPost

QHttpHeaders.WellKnownHeader.AcceptRanges

QHttpHeaders.WellKnownHeader.AcceptSignature

QHttpHeaders.WellKnownHeader.AccessControlAllowCredentials

QHttpHeaders.WellKnownHeader.AccessControlAllowHeaders

QHttpHeaders.WellKnownHeader.AccessControlAllowMethods

QHttpHeaders.WellKnownHeader.AccessControlAllowOrigin

QHttpHeaders.WellKnownHeader.AccessControlExposeHeaders

QHttpHeaders.WellKnownHeader.AccessControlMaxAge

QHttpHeaders.WellKnownHeader.AccessControlRequestHeaders

QHttpHeaders.WellKnownHeader.AccessControlRequestMethod

QHttpHeaders.WellKnownHeader.Age

QHttpHeaders.WellKnownHeader.Allow

QHttpHeaders.WellKnownHeader.ALPN

QHttpHeaders.WellKnownHeader.AltSvc

QHttpHeaders.WellKnownHeader.AltUsed

QHttpHeaders.WellKnownHeader.Alternates

QHttpHeaders.WellKnownHeader.ApplyToRedirectRef

QHttpHeaders.WellKnownHeader.AuthenticationControl

QHttpHeaders.WellKnownHeader.AuthenticationInfo

QHttpHeaders.WellKnownHeader.Authorization

QHttpHeaders.WellKnownHeader.CacheControl

QHttpHeaders.WellKnownHeader.CacheStatus

QHttpHeaders.WellKnownHeader.CalManagedID

QHttpHeaders.WellKnownHeader.CalDAVTimezones

QHttpHeaders.WellKnownHeader.CapsuleProtocol

QHttpHeaders.WellKnownHeader.CDNCacheControl

QHttpHeaders.WellKnownHeader.CDNLoop

QHttpHeaders.WellKnownHeader.CertNotAfter

QHttpHeaders.WellKnownHeader.CertNotBefore

QHttpHeaders.WellKnownHeader.ClearSiteData

QHttpHeaders.WellKnownHeader.ClientCert

QHttpHeaders.WellKnownHeader.ClientCertChain

QHttpHeaders.WellKnownHeader.Close

QHttpHeaders.WellKnownHeader.Connection

QHttpHeaders.WellKnownHeader.ContentDigest

QHttpHeaders.WellKnownHeader.ContentDisposition

QHttpHeaders.WellKnownHeader.ContentEncoding

QHttpHeaders.WellKnownHeader.ContentID

QHttpHeaders.WellKnownHeader.ContentLanguage

QHttpHeaders.WellKnownHeader.ContentLength

QHttpHeaders.WellKnownHeader.ContentLocation

QHttpHeaders.WellKnownHeader.ContentRange

QHttpHeaders.WellKnownHeader.ContentSecurityPolicy

QHttpHeaders.WellKnownHeader.ContentSecurityPolicyReportOnly

QHttpHeaders.WellKnownHeader.ContentType

QHttpHeaders.WellKnownHeader.Cookie

QHttpHeaders.WellKnownHeader.CrossOriginEmbedderPolicy

QHttpHeaders.WellKnownHeader.CrossOriginEmbedderPolicyReportOnly

QHttpHeaders.WellKnownHeader.CrossOriginOpenerPolicy

QHttpHeaders.WellKnownHeader.CrossOriginOpenerPolicyReportOnly

QHttpHeaders.WellKnownHeader.CrossOriginResourcePolicy

QHttpHeaders.WellKnownHeader.DASL

QHttpHeaders.WellKnownHeader.Date

QHttpHeaders.WellKnownHeader.DAV

QHttpHeaders.WellKnownHeader.DeltaBase

QHttpHeaders.WellKnownHeader.Depth

QHttpHeaders.WellKnownHeader.Destination

QHttpHeaders.WellKnownHeader.DifferentialID

QHttpHeaders.WellKnownHeader.DPoP

QHttpHeaders.WellKnownHeader.DPoPNonce

QHttpHeaders.WellKnownHeader.EarlyData

QHttpHeaders.WellKnownHeader.ETag

QHttpHeaders.WellKnownHeader.Expect

QHttpHeaders.WellKnownHeader.ExpectCT

QHttpHeaders.WellKnownHeader.Expires

QHttpHeaders.WellKnownHeader.Forwarded

QHttpHeaders.WellKnownHeader.From

QHttpHeaders.WellKnownHeader.Hobareg

QHttpHeaders.WellKnownHeader.Host

QHttpHeaders.WellKnownHeader.If

QHttpHeaders.WellKnownHeader.IfMatch

QHttpHeaders.WellKnownHeader.IfModifiedSince

QHttpHeaders.WellKnownHeader.IfNoneMatch

QHttpHeaders.WellKnownHeader.IfRange

QHttpHeaders.WellKnownHeader.IfScheduleTagMatch

QHttpHeaders.WellKnownHeader.IfUnmodifiedSince

QHttpHeaders.WellKnownHeader.IM

QHttpHeaders.WellKnownHeader.IncludeReferredTokenBindingID

QHttpHeaders.WellKnownHeader.KeepAlive

QHttpHeaders.WellKnownHeader.Label

QHttpHeaders.WellKnownHeader.LastEventID

QHttpHeaders.WellKnownHeader.LastModified

QHttpHeaders.WellKnownHeader.Link

QHttpHeaders.WellKnownHeader.Location

QHttpHeaders.WellKnownHeader.LockToken

QHttpHeaders.WellKnownHeader.MaxForwards

QHttpHeaders.WellKnownHeader.MementoDatetime

QHttpHeaders.WellKnownHeader.Meter

QHttpHeaders.WellKnownHeader.MIMEVersion

QHttpHeaders.WellKnownHeader.Negotiate

QHttpHeaders.WellKnownHeader.NEL

QHttpHeaders.WellKnownHeader.ODataEntityId

QHttpHeaders.WellKnownHeader.ODataIsolation

QHttpHeaders.WellKnownHeader.ODataMaxVersion

QHttpHeaders.WellKnownHeader.ODataVersion

QHttpHeaders.WellKnownHeader.OptionalWWWAuthenticate

QHttpHeaders.WellKnownHeader.OrderingType

QHttpHeaders.WellKnownHeader.Origin

QHttpHeaders.WellKnownHeader.OriginAgentCluster

QHttpHeaders.WellKnownHeader.OSCORE

QHttpHeaders.WellKnownHeader.OSLCCoreVersion

QHttpHeaders.WellKnownHeader.Overwrite

QHttpHeaders.WellKnownHeader.PingFrom

QHttpHeaders.WellKnownHeader.PingTo

QHttpHeaders.WellKnownHeader.Position

QHttpHeaders.WellKnownHeader.Prefer

QHttpHeaders.WellKnownHeader.PreferenceApplied

QHttpHeaders.WellKnownHeader.Priority

QHttpHeaders.WellKnownHeader.ProxyAuthenticate

QHttpHeaders.WellKnownHeader.ProxyAuthenticationInfo

QHttpHeaders.WellKnownHeader.ProxyAuthorization

QHttpHeaders.WellKnownHeader.ProxyStatus

QHttpHeaders.WellKnownHeader.PublicKeyPins

QHttpHeaders.WellKnownHeader.PublicKeyPinsReportOnly

QHttpHeaders.WellKnownHeader.Range

QHttpHeaders.WellKnownHeader.RedirectRef

QHttpHeaders.WellKnownHeader.Referer

QHttpHeaders.WellKnownHeader.Refresh

QHttpHeaders.WellKnownHeader.ReplayNonce

QHttpHeaders.WellKnownHeader.ReprDigest

QHttpHeaders.WellKnownHeader.RetryAfter

QHttpHeaders.WellKnownHeader.ScheduleReply

QHttpHeaders.WellKnownHeader.ScheduleTag

QHttpHeaders.WellKnownHeader.SecPurpose

QHttpHeaders.WellKnownHeader.SecTokenBinding

QHttpHeaders.WellKnownHeader.SecWebSocketAccept

QHttpHeaders.WellKnownHeader.SecWebSocketExtensions

QHttpHeaders.WellKnownHeader.SecWebSocketKey

QHttpHeaders.WellKnownHeader.SecWebSocketProtocol

QHttpHeaders.WellKnownHeader.SecWebSocketVersion

QHttpHeaders.WellKnownHeader.Server

QHttpHeaders.WellKnownHeader.ServerTiming

QHttpHeaders.WellKnownHeader.SetCookie

QHttpHeaders.WellKnownHeader.Signature

QHttpHeaders.WellKnownHeader.SignatureInput

QHttpHeaders.WellKnownHeader.SLUG

QHttpHeaders.WellKnownHeader.SoapAction

QHttpHeaders.WellKnownHeader.StatusURI

QHttpHeaders.WellKnownHeader.StrictTransportSecurity

QHttpHeaders.WellKnownHeader.Sunset

QHttpHeaders.WellKnownHeader.SurrogateCapability

QHttpHeaders.WellKnownHeader.SurrogateControl

QHttpHeaders.WellKnownHeader.TCN

QHttpHeaders.WellKnownHeader.TE

QHttpHeaders.WellKnownHeader.Timeout

QHttpHeaders.WellKnownHeader.Topic

QHttpHeaders.WellKnownHeader.Traceparent

QHttpHeaders.WellKnownHeader.Tracestate

QHttpHeaders.WellKnownHeader.Trailer

QHttpHeaders.WellKnownHeader.TransferEncoding

QHttpHeaders.WellKnownHeader.TTL

QHttpHeaders.WellKnownHeader.Upgrade

QHttpHeaders.WellKnownHeader.Urgency

QHttpHeaders.WellKnownHeader.UserAgent

QHttpHeaders.WellKnownHeader.VariantVary

QHttpHeaders.WellKnownHeader.Vary

QHttpHeaders.WellKnownHeader.Via

QHttpHeaders.WellKnownHeader.WantContentDigest

QHttpHeaders.WellKnownHeader.WantReprDigest

QHttpHeaders.WellKnownHeader.WWWAuthenticate

QHttpHeaders.WellKnownHeader.XContentTypeOptions

QHttpHeaders.WellKnownHeader.XFrameOptions

QHttpHeaders.WellKnownHeader.AcceptCharset

QHttpHeaders.WellKnownHeader.CPEPInfo

QHttpHeaders.WellKnownHeader.Pragma

QHttpHeaders.WellKnownHeader.ProtocolInfo

QHttpHeaders.WellKnownHeader.ProtocolQuery

__init__(other)#
参数:

otherQHttpHeaders

创建 other 的副本。

__init__()

创建一个新的 QHttpHeaders 对象。

append(name, value)#
参数:
  • name – str

  • value – str

返回类型::

bool

追加一个名为 name 且值为 value 的头信息项,并返回 true 表示成功。

另请参阅

WellKnownHeader, QAnyStringView) Allowed field name and value characters

append(name, value)
参数:
返回类型::

bool

此函数重载了 append(QAnyStringView, QAnyStringView)

clear()#

清除所有头信息项。

另请参阅

size()

combinedValue(name)#
参数:

name – str

返回类型::

QByteArray

返回头信息 name 的值构成的逗号分隔字符串。如果不存在名为 name 的头信息,则返回一个空的 QByteArray。

注意

以这种方式访问“Set-Cookie”头部的值可能不会按预期工作。在HTTP RFC中,这被视为一个显著的例外,因为其值不能以这种方式合并。请首选使用values()方法。

另请参阅

values(QAnyStringView)

combinedValue(name)
参数:

nameWellKnownHeader

返回类型::

QByteArray

此函数重载了combinedValue(QAnyStringView)

contains(name)#
参数:

name – str

返回类型::

bool

返回头是否包含具有name的头。

另请参阅

WellKnownHeader)

contains(name)
参数:

nameWellKnownHeader

返回类型::

bool

此函数重载了has(QAnyStringView)。

static fromListOfPairs(headers)#
参数:

headers – std.pair QByteArray, QByteArray 的列表

返回类型::

QHttpHeaders

创建一个新的 QHttpHeaders 对象,该对象包含 headers

另请参阅

允许的字段名和值字符

static fromMultiHash(headers)#
参数:

headers – QMultiHashQByteArray, QByteArray

返回类型::

QHttpHeaders

创建一个新的 QHttpHeaders 对象,该对象包含 headers

另请参阅

允许的字段名和值字符

static fromMultiMap(headers)#
参数:

headers – QMultiMapQByteArray, QByteArray

返回类型::

QHttpHeaders

创建一个新的 QHttpHeaders 对象,该对象包含 headers

另请参阅

允许的字段名和值字符

insert(i, name, value)#
参数:
  • i – int

  • name – str

  • value – str

返回类型::

bool

在索引 i 处插入一个包含 namevalue 的头条目。索引必须是有效的(见 size())。返回插入是否成功。

另请参阅

append() WellKnownHeader, QAnyStringView) size() Allowed field name and value characters

insert(i, name, value)
参数:
返回类型::

bool

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

isEmpty()#
返回类型::

bool

如果头部大小为 0,则返回 true;否则返回 false

另请参阅

size()

nameAt(i)#
参数:

i – int

返回类型::

QLatin1String

返回索引 i 位置的头部名称。索引 i 必须有效(参见 size())。

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

另请参阅

size() valueAt()

removeAll(name)#
参数:

name – str

移除名为 name 的头部。

另请参阅

removeAt() WellKnownHeader)

removeAll(name)
参数:

nameWellKnownHeader

该函数重载了 removeAll(QAnyStringView)

removeAt(i)#
参数:

i – int

移除索引为 i 的头部。索引 i 必须有效(参见 size())。

另请参阅

WellKnownHeader) removeAll(QAnyStringView) size()

replace(i, name, newValue)#
参数:
  • i – int

  • name – str

  • newValue – str

返回类型::

bool

替换索引为 i 的标题条目,使用 namenewValue。索引必须是有效的(参见 size())。返回替换是否成功。

另请参阅

append() WellKnownHeader, QAnyStringView) size() Allowed field name and value characters

replace(i, name, newValue)
参数:
返回类型::

bool

此函数覆盖了 replace(qsizetype, QAnyStringView, QAnyStringView)

reserve(size)#
参数:

size – int

尝试为至少 size 个标题条目分配内存。

如果您提前知道将有多少个标题条目,可以调用此函数以防止重新分配和内存碎片化。

size()#
返回类型::

int

返回标题条目的数量。

swap(other)#
参数:

otherQHttpHeaders

将此 QHttpHeadersother 交换。此函数非常快速且从不失败。

toListOfPairs()#
返回类型::

列表,包含 std.pair QByteArray, QByteArray

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

toMultiHash()#
返回类型::

.QMultiHashQByteArray, QByteArray

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

toMultiMap()#
返回类型::

.QMultiMapQByteArray, QByteArray

将标题条目作为从名称到值的映射返回。标题名称不区分大小写,返回的名称为小写。

value(name[, defaultValue={}])#
参数:
  • name – str

  • defaultValueQByteArrayView

返回类型::

QByteArrayView

返回(第一个)标题 name 的值,如果不存在则返回 defaultValue

另请参阅

WellKnownHeader, QByteArrayView)

value(name[, defaultValue={}])
参数:
返回类型::

QByteArrayView

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

valueAt(i)#
参数:

i – int

返回类型::

QByteArrayView

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

values(name)#
参数:

name – str

返回类型::

. QByteArray 对象列表

返回头部 name 的值列表。如果不存在具有 name 的头部,则返回空列表。

另请参阅

WellKnownHeader)

values(name)
参数:

nameWellKnownHeader

返回类型::

. QByteArray 对象列表

此函数重载了 values(QAnyStringView)

静态 wellKnownHeaderName(name)#
参数:

nameWellKnownHeader

返回类型::

QByteArrayView

返回与提供的 name 对应的头部名称视图。