class QHttpHeaders#

QHttpHeaders is a class for holding HTTP headers. More

New in version 6.7.

Synopsis#

Methods#

Static functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

The class is an interface type for Qt networking APIs that use or consume such headers.

Allowed field name and value characters#

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 .

Broadly speaking, this means:

  • name must consist of visible ASCII characters, and must not be empty

  • value may consist of arbitrary bytes, as long as header and use case specific encoding rules are adhered to. value may be empty

Furthermore, value may have historically contained leading or trailing whitespace, which has to be ignored while processing such values. The setters of this class automatically remove any such whitespace.

Combining values#

Most HTTP header values can be combined with a single comma ',', 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, as well as due to the possibility of custom use cases, QHttpHeaders does not automatically combine the values.

class WellKnownHeader#

List of well known headers as per IANA registry .

Constant

Description

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)#
Parameters:

otherQHttpHeaders

Creates a copy of other.

__init__()

Creates a new QHttpHeaders object.

append(name, value)#
Parameters:
  • name – str

  • value – str

Return type:

bool

Appends a header entry with name and value and returns true if successful.

See also

WellKnownHeader, QAnyStringView) Allowed field name and value characters

append(name, value)
Parameters:
Return type:

bool

This function overloads append(QAnyStringView, QAnyStringView) .

clear()#

Clears all header entries.

See also

size()

combinedValue(name)#
Parameters:

name – str

Return type:

QByteArray

Returns the values of header name in a comma-combined string. Returns a null QByteArray if the header with name doesn’t exist.

Note

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() instead.

See also

values(QAnyStringView)

combinedValue(name)
Parameters:

nameWellKnownHeader

Return type:

QByteArray

This function overloads combinedValue(QAnyStringView) .

contains(name)#
Parameters:

name – str

Return type:

bool

Returns whether the headers contain header with name.

See also

WellKnownHeader)

contains(name)
Parameters:

nameWellKnownHeader

Return type:

bool

This function overloads has(QAnyStringView).

static fromListOfPairs(headers)#
Parameters:

headers – .list of std.pair QByteArray,QByteArray

Return type:

QHttpHeaders

Creates a new QHttpHeaders object that is populated with headers.

See also

Allowed field name and value characters

static fromMultiHash(headers)#
Parameters:

headers – .QMultiHashQByteArray,QByteArray

Return type:

QHttpHeaders

Creates a new QHttpHeaders object that is populated with headers.

See also

Allowed field name and value characters

static fromMultiMap(headers)#
Parameters:

headers – .QMultiMapQByteArray,QByteArray

Return type:

QHttpHeaders

Creates a new QHttpHeaders object that is populated with headers.

See also

Allowed field name and value characters

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

  • name – str

  • value – str

Return type:

bool

Inserts a header entry at index i, with name and value. The index must be valid (see size() ). Returns whether the insert succeeded.

See also

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

insert(i, name, value)
Parameters:
Return type:

bool

This function overloads insert(qsizetype, QAnyStringView, QAnyStringView) .

isEmpty()#
Return type:

bool

Returns true if the headers have size 0; otherwise returns false.

See also

size()

nameAt(i)#
Parameters:

i – int

Return type:

QLatin1String

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.

See also

size() valueAt()

removeAll(name)#
Parameters:

name – str

Removes the header name.

See also

removeAt() WellKnownHeader)

removeAll(name)
Parameters:

nameWellKnownHeader

This function overloads removeAll(QAnyStringView) .

removeAt(i)#
Parameters:

i – int

Removes the header at index i. The index i must be valid (see size() ).

See also

WellKnownHeader) removeAll(QAnyStringView) size()

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

  • name – str

  • newValue – str

Return type:

bool

Replaces the header entry at index i, with name and newValue. The index must be valid (see size() ). Returns whether the replace succeeded.

See also

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

replace(i, name, newValue)
Parameters:
Return type:

bool

This function overloads replace(qsizetype, QAnyStringView, QAnyStringView) .

reserve(size)#
Parameters:

size – int

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.

size()#
Return type:

int

Returns the number of header entries.

swap(other)#
Parameters:

otherQHttpHeaders

Swaps this QHttpHeaders with other. This function is very fast and never fails.

toListOfPairs()#
Return type:

.list of std.pair QByteArray,QByteArray

Returns the header entries as a list of (name, value) pairs. Header names are case-insensitive, and the returned names are lower-cased.

toMultiHash()#
Return type:

.QMultiHashQByteArray,QByteArray

Returns the header entries as a hash from name to value(s). Header names are case-insensitive, and the returned names are lower-cased.

toMultiMap()#
Return type:

.QMultiMapQByteArray,QByteArray

Returns the header entries as a map from name to value(s). Header names are case-insensitive, and the returned names are lower-cased.

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

  • defaultValueQByteArrayView

Return type:

QByteArrayView

Returns the value of the (first) header name, or defaultValue if it doesn’t exist.

See also

WellKnownHeader, QByteArrayView)

value(name[, defaultValue={}])
Parameters:
Return type:

QByteArrayView

This function overloads value(QAnyStringView, QByteArrayView) .

valueAt(i)#
Parameters:

i – int

Return type:

QByteArrayView

Returns the header value at index i. The index i must be valid (see size() ).

values(name)#
Parameters:

name – str

Return type:

.list of QByteArray

Returns the values of header name in a list. Returns an empty list if header with name doesn’t exist.

See also

WellKnownHeader)

values(name)
Parameters:

nameWellKnownHeader

Return type:

.list of QByteArray

This function overloads values(QAnyStringView) .

static wellKnownHeaderName(name)#
Parameters:

nameWellKnownHeader

Return type:

QByteArrayView

Returns a header name corresponding to the provided name as a view.