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 <QtCore/QSharedDataPointer>
9#include <QtCore/QString>
10#include <QtCore/QUrl>
11#include <QtCore/QVariant>
12
13QT_BEGIN_NAMESPACE
14
15class QSslConfiguration;
16class QHttp2Configuration;
17class QHttp1Configuration;
18
19class QNetworkRequestPrivate;
20class Q_NETWORK_EXPORT QNetworkRequest
21{
22public:
23 enum KnownHeaders {
24 ContentTypeHeader,
25 ContentLengthHeader,
26 LocationHeader,
27 LastModifiedHeader,
28 CookieHeader,
29 SetCookieHeader,
30 ContentDispositionHeader, // added for QMultipartMessage
31 UserAgentHeader,
32 ServerHeader,
33 IfModifiedSinceHeader,
34 ETagHeader,
35 IfMatchHeader,
36 IfNoneMatchHeader
37 };
38 enum Attribute {
39 HttpStatusCodeAttribute,
40 HttpReasonPhraseAttribute,
41 RedirectionTargetAttribute,
42 ConnectionEncryptedAttribute,
43 CacheLoadControlAttribute,
44 CacheSaveControlAttribute,
45 SourceIsFromCacheAttribute,
46 DoNotBufferUploadDataAttribute,
47 HttpPipeliningAllowedAttribute,
48 HttpPipeliningWasUsedAttribute,
49 CustomVerbAttribute,
50 CookieLoadControlAttribute,
51 AuthenticationReuseAttribute,
52 CookieSaveControlAttribute,
53 MaximumDownloadBufferSizeAttribute, // internal
54 DownloadBufferAttribute, // internal
55 SynchronousRequestAttribute, // internal
56 BackgroundRequestAttribute,
57 EmitAllUploadProgressSignalsAttribute,
58 Http2AllowedAttribute,
59 Http2WasUsedAttribute,
60 OriginalContentLengthAttribute,
61 RedirectPolicyAttribute,
62 Http2DirectAttribute,
63 ResourceTypeAttribute, // internal
64 AutoDeleteReplyOnFinishAttribute,
65 ConnectionCacheExpiryTimeoutSecondsAttribute,
66 Http2CleartextAllowedAttribute,
67 UseCredentialsAttribute,
68
69 User = 1000,
70 UserMax = 32767
71 };
72 enum CacheLoadControl {
73 AlwaysNetwork,
74 PreferNetwork,
75 PreferCache,
76 AlwaysCache
77 };
78 enum LoadControl {
79 Automatic = 0,
80 Manual
81 };
82
83 enum Priority {
84 HighPriority = 1,
85 NormalPriority = 3,
86 LowPriority = 5
87 };
88
89 enum RedirectPolicy {
90 ManualRedirectPolicy,
91 NoLessSafeRedirectPolicy,
92 SameOriginRedirectPolicy,
93 UserVerifiedRedirectPolicy
94 };
95
96 enum TransferTimeoutConstant {
97 DefaultTransferTimeoutConstant = 30000
98 };
99
100 QNetworkRequest();
101 explicit QNetworkRequest(const QUrl &url);
102 QNetworkRequest(const QNetworkRequest &other);
103 ~QNetworkRequest();
104 QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; }
105 QNetworkRequest &operator=(const QNetworkRequest &other);
106
107 void swap(QNetworkRequest &other) noexcept { d.swap(other&: other.d); }
108
109 bool operator==(const QNetworkRequest &other) const;
110 inline bool operator!=(const QNetworkRequest &other) const
111 { return !operator==(other); }
112
113 QUrl url() const;
114 void setUrl(const QUrl &url);
115
116 // "cooked" headers
117 QVariant header(KnownHeaders header) const;
118 void setHeader(KnownHeaders header, const QVariant &value);
119
120 // raw headers:
121 bool hasRawHeader(const QByteArray &headerName) const;
122 QList<QByteArray> rawHeaderList() const;
123 QByteArray rawHeader(const QByteArray &headerName) const;
124 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
125
126 // attributes
127 QVariant attribute(Attribute code, const QVariant &defaultValue = QVariant()) const;
128 void setAttribute(Attribute code, const QVariant &value);
129
130#ifndef QT_NO_SSL
131 QSslConfiguration sslConfiguration() const;
132 void setSslConfiguration(const QSslConfiguration &configuration);
133#endif
134
135 void setOriginatingObject(QObject *object);
136 QObject *originatingObject() const;
137
138 Priority priority() const;
139 void setPriority(Priority priority);
140
141 // HTTP redirect related
142 int maximumRedirectsAllowed() const;
143 void setMaximumRedirectsAllowed(int maximumRedirectsAllowed);
144
145 QString peerVerifyName() const;
146 void setPeerVerifyName(const QString &peerName);
147#if QT_CONFIG(http)
148 QHttp1Configuration http1Configuration() const;
149 void setHttp1Configuration(const QHttp1Configuration &configuration);
150
151 QHttp2Configuration http2Configuration() const;
152 void setHttp2Configuration(const QHttp2Configuration &configuration);
153
154 qint64 decompressedSafetyCheckThreshold() const;
155 void setDecompressedSafetyCheckThreshold(qint64 threshold);
156#endif // QT_CONFIG(http)
157
158#if QT_CONFIG(http) || defined (Q_OS_WASM)
159 int transferTimeout() const;
160 void setTransferTimeout(int timeout = DefaultTransferTimeoutConstant);
161#endif // QT_CONFIG(http) || defined (Q_OS_WASM)
162private:
163 QSharedDataPointer<QNetworkRequestPrivate> d;
164 friend class QNetworkRequestPrivate;
165};
166
167Q_DECLARE_SHARED(QNetworkRequest)
168
169QT_END_NAMESPACE
170
171QT_DECL_METATYPE_EXTERN(QNetworkRequest, Q_NETWORK_EXPORT)
172QT_DECL_METATYPE_EXTERN_TAGGED(QNetworkRequest::RedirectPolicy,
173 QNetworkRequest__RedirectPolicy, Q_NETWORK_EXPORT)
174
175#endif
176

source code of qtbase/src/network/access/qnetworkrequest.h