1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qhttp1configuration.h" |
5 | |
6 | #include <QtCore/private/qnumeric_p.h> |
7 | #include <QtCore/qhashfunctions.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | // QHttp1ConfigurationPrivate is unused until we need it: |
12 | static_assert(sizeof(QHttp1Configuration) == sizeof(void*), |
13 | "You have added too many members to QHttp1Configuration::ShortData. " |
14 | "Decrease their size or switch to using a d-pointer." ); |
15 | |
16 | /*! |
17 | \class QHttp1Configuration |
18 | \brief The QHttp1Configuration class controls HTTP/1 parameters and settings. |
19 | \since 6.5 |
20 | |
21 | \reentrant |
22 | \inmodule QtNetwork |
23 | \ingroup network |
24 | \ingroup shared |
25 | |
26 | QHttp1Configuration controls HTTP/1 parameters and settings that |
27 | QNetworkAccessManager will use to send requests and process responses. |
28 | |
29 | \note The configuration must be set before the first request |
30 | was sent to a given host (and thus an HTTP/1 session established). |
31 | |
32 | \sa QNetworkRequest::setHttp1Configuration(), QNetworkRequest::http1Configuration(), QNetworkAccessManager |
33 | */ |
34 | |
35 | /*! |
36 | Default constructs a QHttp1Configuration object. |
37 | */ |
38 | QHttp1Configuration::QHttp1Configuration() |
39 | : u(ShortData{.numConnectionsPerHost: 6, .reserved: {}}) // QHttpNetworkConnectionPrivate::defaultHttpChannelCount |
40 | { |
41 | } |
42 | |
43 | /*! |
44 | Copy-constructs this QHttp1Configuration. |
45 | */ |
46 | QHttp1Configuration::QHttp1Configuration(const QHttp1Configuration &) |
47 | = default; |
48 | |
49 | /*! |
50 | \fn QHttp1Configuration::QHttp1Configuration(QHttp1Configuration &&other) |
51 | |
52 | Move-constructs this QHttp1Configuration from \a other. |
53 | |
54 | \note The moved-from object \a other is placed in a |
55 | partially-formed state, in which the only valid operations are |
56 | destruction and assignment of a new value. |
57 | */ |
58 | |
59 | /*! |
60 | Copy-assigns \a other to this QHttp1Configuration. |
61 | */ |
62 | QHttp1Configuration &QHttp1Configuration::operator=(const QHttp1Configuration &) |
63 | = default; |
64 | |
65 | /*! |
66 | \fn QHttp1Configuration &QHttp1Configuration::operator=(QHttp1Configuration &&) |
67 | |
68 | Move-assigns \a other to this QHttp1Configuration. |
69 | |
70 | \note The moved-from object \a other is placed in a |
71 | partially-formed state, in which the only valid operations are |
72 | destruction and assignment of a new value. |
73 | */ |
74 | |
75 | /*! |
76 | Destructor. |
77 | */ |
78 | QHttp1Configuration::~QHttp1Configuration() |
79 | = default; |
80 | |
81 | /*! |
82 | Sets the number of connections (minimum: 1; maximum: 255) |
83 | used per http(s) \e{host}:\e{port} combination to \a number. |
84 | |
85 | If \a number is ≤ 0, does nothing. If \a number is > 255, 255 is used. |
86 | |
87 | \sa numberOfConnectionsPerHost |
88 | */ |
89 | void QHttp1Configuration::setNumberOfConnectionsPerHost(qsizetype number) |
90 | { |
91 | auto n = qt_saturate<std::uint8_t>(x: number); |
92 | if (n == 0) |
93 | return; |
94 | u.data.numConnectionsPerHost = n; |
95 | } |
96 | |
97 | /*! |
98 | Returns the number of connections used per http(s) \c{host}:\e{port} |
99 | combination. The default is six (6). |
100 | |
101 | \sa setNumberOfConnectionsPerHost |
102 | */ |
103 | qsizetype QHttp1Configuration::numberOfConnectionsPerHost() const |
104 | { |
105 | return u.data.numConnectionsPerHost; |
106 | } |
107 | |
108 | /*! |
109 | \fn void QHttp1Configuration::swap(QHttp1Configuration &other) |
110 | |
111 | Swaps this HTTP/1 configuration with \a other. This operation is very fast |
112 | and never fails. |
113 | */ |
114 | |
115 | /*! |
116 | \fn bool QHttp1Configuration::operator==(const QHttp1Configuration &lhs, const QHttp1Configuration &rhs) noexcept |
117 | \since 6.5 |
118 | |
119 | Returns \c true if \a lhs and \a rhs represent the same set of HTTP/1 |
120 | parameters. |
121 | */ |
122 | |
123 | /*! |
124 | \fn bool QHttp1Configuration::operator!=(const QHttp1Configuration &lhs, const QHttp1Configuration &rhs) noexcept |
125 | \since 6.5 |
126 | |
127 | Returns \c true if \a lhs and \a rhs do not represent the same set of |
128 | HTTP/1 parameters. |
129 | */ |
130 | |
131 | /*! |
132 | \fn size_t QHttp1Configuration::qHash(const QHttp1Configuration &key, size_t seed) |
133 | \since 6.5 |
134 | |
135 | Returns the hash value for the \a key, using \a seed to seed the calculation. |
136 | */ |
137 | |
138 | /*! |
139 | \internal |
140 | */ |
141 | bool QHttp1Configuration::equals(const QHttp1Configuration &other) const noexcept |
142 | { |
143 | return u.data.numConnectionsPerHost == other.u.data.numConnectionsPerHost; |
144 | } |
145 | |
146 | /*! |
147 | \internal |
148 | */ |
149 | size_t QHttp1Configuration::hash(size_t seed) const noexcept |
150 | { |
151 | return qHash(key: u.data.numConnectionsPerHost, seed); |
152 | } |
153 | |
154 | QT_END_NAMESPACE |
155 | |