Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qhttpheaders.cpp File Reference

(d8f6425fef1050525480afec662a417a7645c22e)

#include "qhttpheaders.h"
#include <private/qoffsetstringarray_p.h>
#include <QtCore/qcompare.h>
#include <QtCore/qhash.h>
#include <QtCore/qloggingcategory.h>
#include <QtCore/qmap.h>
#include <QtCore/qset.h>
#include <QtCore/qttypetraits.h>
#include <q20algorithm.h>
#include <string_view>
#include <variant>
+ Include dependency graph for qhttpheaders.cpp:

Go to the source code of this file.

Classes

struct  HeaderName
 
struct  Header
 
class  QHttpHeadersPrivate
 

Functions

QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY (lcQHttpHeaders, "qt.network.http.headers")
 
static QByteArray fieldToByteArray (QLatin1StringView s) noexcept
 
static QByteArray fieldToByteArray (QUtf8StringView s) noexcept
 
static QByteArray fieldToByteArray (QStringView s)
 
static QByteArray normalizedName (QAnyStringView name)
 
auto headerNameMatches (const HeaderName &name)
 
QDebug operator<< (QDebug debug, const QHttpHeaders &headers)
 
static bool isUtf8Latin1Representable (QUtf8StringView s) noexcept
 
static bool headerNameValidImpl (QLatin1StringView name) noexcept
 
static bool headerNameValidImpl (QUtf8StringView name) noexcept
 
static bool headerNameValidImpl (QStringView name) noexcept
 
static bool isValidHttpHeaderNameField (QAnyStringView name) noexcept
 
static bool headerValueValidImpl (QLatin1StringView value) noexcept
 
static bool headerValueValidImpl (QUtf8StringView value) noexcept
 
static bool headerValueValidImpl (QStringView value) noexcept
 
static bool isValidHttpHeaderValueField (QAnyStringView value) noexcept
 
static QByteArray normalizedValue (QAnyStringView value)
 

Variables

static constexpr auto headerNames
 
static constexpr quint8 orderedHeaderNameIndexes []
 
static constexpr auto isValidHttpHeaderNameChar
 
static constexpr auto isValidHttpHeaderValueChar
 

Function Documentation

◆ fieldToByteArray() [1/3]

static QByteArray fieldToByteArray ( QLatin1StringView s)
staticnoexcept

Definition at line 675 of file qhttpheaders.cpp.

References QByteArray().

Referenced by normalizedName(), and normalizedValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fieldToByteArray() [2/3]

static QByteArray fieldToByteArray ( QStringView s)
static

Definition at line 685 of file qhttpheaders.cpp.

◆ fieldToByteArray() [3/3]

static QByteArray fieldToByteArray ( QUtf8StringView s)
staticnoexcept

Definition at line 680 of file qhttpheaders.cpp.

References QByteArray().

+ Here is the call graph for this function:

◆ headerNameMatches()

auto headerNameMatches ( const HeaderName & name)

Definition at line 778 of file qhttpheaders.cpp.

References header().

Referenced by QHttpHeaders::contains(), QHttpHeaders::contains(), QHttpHeadersPrivate::removeAll(), and QHttpHeadersPrivate::replaceOrAppend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ headerNameValidImpl() [1/3]

static bool headerNameValidImpl ( QLatin1StringView name)
staticnoexcept

Definition at line 1053 of file qhttpheaders.cpp.

References isValidHttpHeaderNameChar.

Referenced by headerNameValidImpl(), and isValidHttpHeaderNameField().

+ Here is the caller graph for this function:

◆ headerNameValidImpl() [2/3]

static bool headerNameValidImpl ( QStringView name)
staticnoexcept

Definition at line 1066 of file qhttpheaders.cpp.

◆ headerNameValidImpl() [3/3]

static bool headerNameValidImpl ( QUtf8StringView name)
staticnoexcept

Definition at line 1058 of file qhttpheaders.cpp.

References headerNameValidImpl().

+ Here is the call graph for this function:

◆ headerValueValidImpl() [1/3]

static bool headerValueValidImpl ( QLatin1StringView value)
staticnoexcept

Definition at line 1102 of file qhttpheaders.cpp.

References isValidHttpHeaderValueChar.

Referenced by isValidHttpHeaderValueField().

+ Here is the caller graph for this function:

◆ headerValueValidImpl() [2/3]

static bool headerValueValidImpl ( QStringView value)
staticnoexcept

Definition at line 1114 of file qhttpheaders.cpp.

◆ headerValueValidImpl() [3/3]

static bool headerValueValidImpl ( QUtf8StringView value)
staticnoexcept

Definition at line 1107 of file qhttpheaders.cpp.

References isUtf8Latin1Representable(), and isValidHttpHeaderValueChar.

+ Here is the call graph for this function:

◆ isUtf8Latin1Representable()

static bool isUtf8Latin1Representable ( QUtf8StringView s)
staticnoexcept

Definition at line 1000 of file qhttpheaders.cpp.

Referenced by headerValueValidImpl().

+ Here is the caller graph for this function:

◆ isValidHttpHeaderNameField()

static bool isValidHttpHeaderNameField ( QAnyStringView name)
staticnoexcept

Definition at line 1073 of file qhttpheaders.cpp.

References headerNameValidImpl(), and qCWarning.

Referenced by QHttpHeaders::append(), QHttpHeaders::insert(), QHttpHeaders::replace(), and QHttpHeaders::replaceOrAppend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidHttpHeaderValueField()

static bool isValidHttpHeaderValueField ( QAnyStringView value)
staticnoexcept

Definition at line 1121 of file qhttpheaders.cpp.

References headerValueValidImpl(), and qCWarning.

Referenced by QHttpHeaders::append(), QHttpHeaders::append(), QHttpHeaders::insert(), QHttpHeaders::insert(), QHttpHeaders::replace(), QHttpHeaders::replace(), QHttpHeaders::replaceOrAppend(), and QHttpHeaders::replaceOrAppend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalizedName()

static QByteArray normalizedName ( QAnyStringView name)
static

Definition at line 690 of file qhttpheaders.cpp.

References fieldToByteArray().

Referenced by HeaderName::HeaderName(), QDBusConnectionPrivate::findSlot(), QDBusConnectionPrivate::prepareHook(), and QDBusPendingCallPrivate::setReplyCallback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalizedValue()

static QByteArray normalizedValue ( QAnyStringView value)
static

Definition at line 1129 of file qhttpheaders.cpp.

References fieldToByteArray().

Referenced by QHttpHeaders::append(), QHttpHeaders::append(), QHttpHeaders::insert(), QHttpHeaders::insert(), QHttpHeaders::replace(), QHttpHeaders::replace(), QHttpHeaders::replaceOrAppend(), and QHttpHeaders::replaceOrAppend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator<<()

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

Definition at line 972 of file qhttpheaders.cpp.

◆ Q_LOGGING_CATEGORY()

QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY ( lcQHttpHeaders ,
"qt.network.http.headers"  )

Variable Documentation

◆ headerNames

constexpr auto headerNames
staticconstexpr
\class QHttpHeaders
\since 6.7
\ingroup
\inmodule QtNetwork

\brief QHttpHeaders is a class for holding HTTP headers.

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

\section1 Allowed field name and value characters

An HTTP header consists of \e name and \e value.
When setting these, QHttpHeaders validates \e name and \e value
to only contain characters allowed by the HTTP RFCs. For detailed
information see
\l {https://datatracker.ietf.org/doc/html/rfc9110#name-field-values}
{RFC 9110 Chapters 5.1 and 5.5}.

In all, this means:
\list
    \li \c name must consist of visible ASCII characters, and must not be
        empty
    \li \c value may consist of arbitrary bytes, as long as header
        and use case specific encoding rules are adhered to. \c value
        may be empty
\endlist

The setters of this class automatically remove any leading or trailing
whitespaces from \e value, as they must be ignored during the
\e value processing.

\section1 Combining values

Most HTTP header values can be combined with a single comma \c {','}
plus an optional whitespace, and the semantic meaning is preserved.
As an example, these two should be semantically similar:
\badcode

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

However, there is a notable exception to this rule: \l {https://datatracker.ietf.org/doc/html/rfc9110#name-field-order} {Set-Cookie}. Due to this and the possibility of custom use cases, QHttpHeaders does not automatically combine the values.

Definition at line 89 of file qhttpheaders.cpp.

Referenced by HeaderName::asByteArray(), HeaderName::asView(), HeaderName::toWellKnownHeader(), and QHttpHeaders::wellKnownHeaderName().

◆ isValidHttpHeaderNameChar

constexpr auto isValidHttpHeaderNameChar
staticconstexpr
Initial value:
= [](uchar c) noexcept
{
return (('A' <= c && c <= 'Z')
|| ('a' <= c && c <= 'z')
|| ('0' <= c && c <= '9')
|| ('#' <= c && c <= '\'')
|| ('^' <= c && c <= '`')
|| c == '|' || c == '~' || c == '!' || c == '*' || c == '+' || c == '-' || c == '.');
}
const GLubyte * c
unsigned char uchar
Definition qtypes.h:32

Definition at line 1035 of file qhttpheaders.cpp.

Referenced by headerNameValidImpl().

◆ isValidHttpHeaderValueChar

constexpr auto isValidHttpHeaderValueChar
staticconstexpr
Initial value:
= [](uchar c) noexcept
{
return (c >= 0x80
|| (0x20 <= c && c <= 0x7E)
|| (c == 0x09));
}

Definition at line 1085 of file qhttpheaders.cpp.

Referenced by headerValueValidImpl(), and headerValueValidImpl().

◆ orderedHeaderNameIndexes

constexpr quint8 orderedHeaderNameIndexes[]
staticconstexpr

Definition at line 306 of file qhttpheaders.cpp.

Referenced by HeaderName::toWellKnownHeader().