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
qnetworkrequest.h
Go to the documentation of this file.
1// Copyright (C) 2016 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#ifndef QNETWORKREQUEST_H
5#define QNETWORKREQUEST_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtNetwork/qhttpheaders.h>
9#include <QtCore/QSharedDataPointer>
10#include <QtCore/QString>
11#include <QtCore/QUrl>
12#include <QtCore/QVariant>
13
15
19
21class Q_NETWORK_EXPORT QNetworkRequest
22{
24public:
41 Q_ENUM(KnownHeaders)
42
84 Automatic = 0,
85 Manual
86 };
87
88 enum Priority {
89 HighPriority = 1,
90 NormalPriority = 3,
91 LowPriority = 5
92 };
93
100
102 DefaultTransferTimeoutConstant = 30000
103 };
104
105 static constexpr auto DefaultTransferTimeout =
106 std::chrono::milliseconds(DefaultTransferTimeoutConstant);
107
109 explicit QNetworkRequest(const QUrl &url);
112 QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; }
113 QNetworkRequest &operator=(const QNetworkRequest &other);
114
115 void swap(QNetworkRequest &other) noexcept { d.swap(other.d); }
116
117 bool operator==(const QNetworkRequest &other) const;
118 inline bool operator!=(const QNetworkRequest &other) const
119 { return !operator==(other); }
120
121 QUrl url() const;
122 void setUrl(const QUrl &url);
123
124 QHttpHeaders headers() const;
125 void setHeaders(const QHttpHeaders &newHeaders);
126 void setHeaders(QHttpHeaders &&newHeaders);
127
128 // "cooked" headers
129 QVariant header(KnownHeaders header) const;
130 void setHeader(KnownHeaders header, const QVariant &value);
131
132 // raw headers:
133#if QT_NETWORK_REMOVED_SINCE(6, 7)
134 bool hasRawHeader(const QByteArray &headerName) const;
135#endif
136 bool hasRawHeader(QAnyStringView headerName) const;
137 QList<QByteArray> rawHeaderList() const;
138#if QT_NETWORK_REMOVED_SINCE(6, 7)
139 QByteArray rawHeader(const QByteArray &headerName) const;
140#endif
141 QByteArray rawHeader(QAnyStringView headerName) const;
142 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
143
144 // attributes
145 QVariant attribute(Attribute code, const QVariant &defaultValue = QVariant()) const;
146 void setAttribute(Attribute code, const QVariant &value);
147
148#ifndef QT_NO_SSL
149 QSslConfiguration sslConfiguration() const;
150 void setSslConfiguration(const QSslConfiguration &configuration);
151#endif
152
153 void setOriginatingObject(QObject *object);
154 QObject *originatingObject() const;
155
156 Priority priority() const;
157 void setPriority(Priority priority);
158
159 // HTTP redirect related
160 int maximumRedirectsAllowed() const;
161 void setMaximumRedirectsAllowed(int maximumRedirectsAllowed);
162
163 QString peerVerifyName() const;
164 void setPeerVerifyName(const QString &peerName);
165#if QT_CONFIG(http)
166 QHttp1Configuration http1Configuration() const;
167 void setHttp1Configuration(const QHttp1Configuration &configuration);
168
169 QHttp2Configuration http2Configuration() const;
170 void setHttp2Configuration(const QHttp2Configuration &configuration);
171
172 qint64 decompressedSafetyCheckThreshold() const;
173 void setDecompressedSafetyCheckThreshold(qint64 threshold);
174#endif // QT_CONFIG(http)
175
176#if QT_CONFIG(http) || defined (Q_OS_WASM)
177 QT_NETWORK_INLINE_SINCE(6, 8)
178 int transferTimeout() const;
179 QT_NETWORK_INLINE_SINCE(6, 8)
180 void setTransferTimeout(int timeout);
181
182 std::chrono::milliseconds transferTimeoutAsDuration() const;
183 void setTransferTimeout(std::chrono::milliseconds duration = DefaultTransferTimeout);
184#endif // QT_CONFIG(http) || defined (Q_OS_WASM)
185private:
186 QSharedDataPointer<QNetworkRequestPrivate> d;
188};
189
190Q_DECLARE_SHARED(QNetworkRequest)
191
192#if QT_NETWORK_INLINE_IMPL_SINCE(6, 8)
193#if QT_CONFIG(http) || defined (Q_OS_WASM)
194int QNetworkRequest::transferTimeout() const
195{
196 return int(transferTimeoutAsDuration().count());
197}
198
199void QNetworkRequest::setTransferTimeout(int timeout)
200{
201 setTransferTimeout(std::chrono::milliseconds(timeout));
202}
203#endif // QT_CONFIG(http) || defined (Q_OS_WASM)
204#endif // INLINE_SINCE 6.8
205
207
210 QNetworkRequest__RedirectPolicy, Q_NETWORK_EXPORT)
211
212#endif
\inmodule QtCore
\inmodule QtCore
Definition qbytearray.h:57
The QHttp1Configuration class controls HTTP/1 parameters and settings.
The QHttp2Configuration class controls HTTP/2 parameters and settings.
\variable QNetworkRequest::DefaultTransferTimeout
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
KnownHeaders
List of known header types that QNetworkRequest parses.
@ EmitAllUploadProgressSignalsAttribute
@ ConnectionCacheExpiryTimeoutSecondsAttribute
QNetworkRequest & operator=(QNetworkRequest &&other) noexcept
void swap(QNetworkRequest &other) noexcept
bool operator!=(const QNetworkRequest &other) const
Returns false if this object is not the same as other.
CacheLoadControl
Controls the caching mechanism of QNetworkAccessManager.
\inmodule QtCore
Definition qobject.h:103
The QSslConfiguration class holds the configuration and state of an SSL connection.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
myinstance setPriority(MyClass::VeryHigh)
Combined button and popup list for selecting options.
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputLayerEXT EGLint attribute
@ User
#define QT_DECL_METATYPE_EXTERN(TYPE, EXPORT)
Definition qmetatype.h:1388
#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT)
Definition qmetatype.h:1376
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
request setUrl(QUrl("http://qt-project.org"))
#define Q_ENUM(x)
#define Q_GADGET
long long qint64
Definition qtypes.h:60
QUrl url("example.com")
[constructor-url-reference]
QSharedPointer< T > other(t)
[5]
this swap(other)
app setAttribute(Qt::AA_DontShowIconsInMenus)
textPart setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\""))
imagePart setRawHeader("Content-ID", "my@content.id")
sslSocket setSslConfiguration(config)