Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnetworkreplyhttpimpl_p.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// Qt-Security score:significant reason:default
4
5#ifndef QNETWORKREPLYHTTPIMPL_P_H
6#define QNETWORKREPLYHTTPIMPL_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
21#include "qnetworkreply.h"
22
23#include "QtCore/qpointer.h"
24#include "QtCore/qdatetime.h"
25#include "QtCore/qsharedpointer.h"
26#include "QtCore/qtimer.h"
27#include "qatomic.h"
28
29#include <QtNetwork/QNetworkCacheMetaData>
30#include <private/qhttpnetworkrequest_p.h>
31#include <private/qnetworkreply_p.h>
32#include <QtNetwork/QNetworkProxy>
33
34#ifndef QT_NO_SSL
35#include <QtNetwork/QSslConfiguration>
36
37#include <memory>
38#endif
39
40Q_MOC_INCLUDE(<QtNetwork/QAuthenticator>)
41
42#include <private/qdecompresshelper_p.h>
43
44#include <memory>
45
46QT_REQUIRE_CONFIG(http);
47
48QT_BEGIN_NAMESPACE
49
50class QIODevice;
51
54{
56public:
58 virtual ~QNetworkReplyHttpImpl();
59
60 void close() override;
61 void abort() override;
62 void abortImpl(QNetworkReply::NetworkError error);
63 qint64 bytesAvailable() const override;
64 bool isSequential () const override;
65 qint64 size() const override;
66 qint64 readData(char*, qint64) override;
67 void setReadBufferSize(qint64 size) override;
68 bool canReadLine () const override;
69
78
79 // From reply
85#ifndef QT_NO_SSL
90#endif
91#ifndef QT_NO_NETWORKPROXY
93#endif
94
102 Q_PRIVATE_SLOT(d_func(), void onRedirected(const QUrl &, int, int))
104
105#ifndef QT_NO_SSL
106protected:
108 void ignoreSslErrorsImplementation(const QList<QSslError> &errors) override;
109 void setSslConfigurationImplementation(const QSslConfiguration &configuration) override;
110 void sslConfigurationImplementation(QSslConfiguration &configuration) const override;
111#endif
112
113signals:
114 // To HTTP thread:
117 void readBufferSizeChanged(qint64 size);
118 void readBufferFreed(qint64 size);
119
121
122 void haveUploadData(const qint64 pos, const QByteArray &dataArray, bool dataAtEnd, qint64 dataSize);
123};
124
126{
127public:
128
129 static QHttpNetworkRequest::Priority convert(QNetworkRequest::Priority prio);
130
133
134 void _q_startOperation();
135
137
140
142
143 void _q_transferTimedOut();
145
146 void _q_finished();
147
148 void finished();
149 void error(QNetworkReply::NetworkError code, const QString &errorString);
150 void _q_error(QNetworkReply::NetworkError code, const QString &errorString);
151 void _q_metaDataChanged();
152
153 void checkForRedirect(const int statusCode);
154
155 // incoming from user
158 QHttpNetworkRequest httpRequest; // There is also a copy in the HTTP thread
160
162
163 // from http thread
166
167 // upload
168 void maybeDropUploadDevice(const QNetworkRequest &newHttpRequest);
172 bool uploadDeviceChoking; // if we couldn't readPointer() any data at the moment
173 QIODevice *outgoingData;
175 void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); // dup?
176 void onRedirected(const QUrl &redirectUrl, int httpStatus, int maxRedirectsRemainig);
177 void followRedirect();
179
180
181 // cache
182 void createCache();
183 void completeCacheSave();
184 void setCachingEnabled(bool enable);
185 bool isCachingEnabled() const;
186 bool isCachingAllowed() const;
187 void initCacheSaveDevice();
188 QIODevice *cacheLoadDevice;
190
191 QIODevice *cacheSaveDevice;
192 bool cacheEnabled; // is this for saving?
193
194
196#ifndef QT_NO_NETWORKPROXY
198#endif
199
200
201 bool canResume() const;
202 void setResumeOffset(quint64 offset);
204
207 // We use this to keep track of whether or not we need to emit readyRead
208 // when we deal with signal compression (delaying emission) + decompressing
209 // data (potentially receiving bytes that don't end up in the final output):
211
213
214 // Only used when the "zero copy" style is used.
215 // Please note that the whole "zero copy" download buffer API is private right now. Do not use it.
220
221 // Will be increased by HTTP thread:
224
225
226#ifndef QT_NO_SSL
230#endif
231
233
235
236 bool loadFromCacheIfAllowed(QHttpNetworkRequest &httpRequest);
237 void invalidateCache();
238 bool sendCacheContents(const QNetworkCacheMetaData &metaData);
239 QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const;
240
241
242 void postRequest(const QNetworkRequest& newHttpRequest);
243 QNetworkAccessManager::Operation getRedirectOperation(QNetworkAccessManager::Operation currentOp, int httpStatus);
244 QNetworkRequest createRedirectRequest(const QNetworkRequest &originalRequests, const QUrl &url, int maxRedirectsRemainig);
245 bool isHttpRedirectResponse() const;
246
247public:
248 // From HTTP thread:
250 void replyFinished();
251 void replyDownloadMetaData(const QHttpHeaders &, int, const QString &,
252 bool, QSharedPointer<char>, qint64, qint64, bool, bool);
254 void httpAuthenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *auth);
255 void httpError(QNetworkReply::NetworkError error, const QString &errorString);
256#ifndef QT_NO_SSL
257 void replyEncrypted();
258 void replySslErrors(const QList<QSslError> &, bool *, QList<QSslError> *);
259 void replySslConfigurationChanged(const QSslConfiguration &newSslConfiguration);
261#endif
262#ifndef QT_NO_NETWORKPROXY
263 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
264#endif
265
266 // From QNonContiguousByteDeviceThreadForwardImpl in HTTP thread:
267 void resetUploadDataSlot(bool *r);
270
271 // From user's QNonContiguousByteDevice
273
274 Q_DECLARE_PUBLIC(QNetworkReplyHttpImpl)
275};
276
277QT_END_NAMESPACE
278
279#endif
\inmodule QtCore
Definition qatomic.h:114
The QNetworkCacheMetaData class provides cache information.
static QByteArray fromCookieList(const NetworkCookieList &cookies)
QNetworkRequest createRedirectRequest(const QNetworkRequest &originalRequests, const QUrl &url, int maxRedirectsRemainig)
QSharedPointer< char > downloadBufferPointer
QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const
void _q_error(QNetworkReply::NetworkError code, const QString &errorString)
void httpError(QNetworkReply::NetworkError error, const QString &errorString)
std::shared_ptr< QAtomicInt > pendingDownloadProgressEmissions
QNetworkAccessManagerPrivate * managerPrivate
void replyDownloadMetaData(const QHttpHeaders &, int, const QString &, bool, QSharedPointer< char >, qint64, qint64, bool, bool)
void replySslConfigurationChanged(const QSslConfiguration &newSslConfiguration)
void onRedirected(const QUrl &redirectUrl, int httpStatus, int maxRedirectsRemainig)
void maybeDropUploadDevice(const QNetworkRequest &newHttpRequest)
void error(QNetworkReply::NetworkError code, const QString &errorString)
QNetworkAccessManager::Operation getRedirectOperation(QNetworkAccessManager::Operation currentOp, int httpStatus)
std::shared_ptr< QNonContiguousByteDevice > uploadByteDevice
void httpAuthenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *auth)
void replyDownloadProgressSlot(qint64, qint64)
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth)
bool sendCacheContents(const QNetworkCacheMetaData &metaData)
void checkForRedirect(const int statusCode)
QNonContiguousByteDevice * createUploadByteDevice()
std::shared_ptr< QAtomicInt > pendingDownloadDataEmissions
void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal)
void replySslErrors(const QList< QSslError > &, bool *, QList< QSslError > *)
bool loadFromCacheIfAllowed(QHttpNetworkRequest &httpRequest)
std::shared_ptr< QRingBuffer > outgoingDataBuffer
std::unique_ptr< QSslConfiguration > sslConfiguration
void replyPreSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator *)
void postRequest(const QNetworkRequest &newHttpRequest)
static QHttpNetworkRequest::Priority convert(QNetworkRequest::Priority prio)
qint64 readData(char *, qint64) override
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
void readBufferFreed(qint64 size)
void setSslConfigurationImplementation(const QSslConfiguration &configuration) override
void readBufferSizeChanged(qint64 size)
void abort() override
Aborts the operation immediately and closes any network connections still open.
void close() override
Closes this device for reading.
void haveUploadData(const qint64 pos, const QByteArray &dataArray, bool dataAtEnd, qint64 dataSize)
qint64 size() const override
For open random-access devices, this function returns the size of the device.
void abortImpl(QNetworkReply::NetworkError error)
void startHttpRequestSynchronously()
void void void void void void void void void void void void void void void void void void void void void void void void void followRedirect()) protected void ignoreSslErrorsImplementation(const QList< QSslError > &errors) override
void sslConfigurationImplementation(QSslConfiguration &configuration) const override
qint64 bytesAvailable() const override
Returns the number of bytes that are available for reading.
bool isSequential() const override
bool canReadLine() const override
Returns true if a complete line of data can be read from the device; otherwise returns false.
void setReadBufferSize(qint64 size) override
Sets the size of the read buffer to be size bytes.
\inmodule QtCore
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
static QByteArray cacheControlName()
static constexpr QLatin1StringView locationHeader() noexcept
static auto remapCustom(QNetworkAccessManager::Operation operation, const QNetworkRequest &req)
static auto caseInsensitiveCompare(QByteArrayView value)
static QByteArray rangeName()
static bool isHopByHop(QByteArrayView header)
static constexpr QByteArrayView bytesEqualPrefix() noexcept
static QHash< QByteArray, QByteArray > parseHttpOptionHeader(QByteArrayView header)