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 qint64 bytesAvailable() const override;
63 bool isSequential () const override;
64 qint64 size() const override;
65 qint64 readData(char*, qint64) override;
66 void setReadBufferSize(qint64 size) override;
67 bool canReadLine () const override;
68
77
78 // From reply
84#ifndef QT_NO_SSL
89#endif
90#ifndef QT_NO_NETWORKPROXY
92#endif
93
101 Q_PRIVATE_SLOT(d_func(), void onRedirected(const QUrl &, int, int))
103
104#ifndef QT_NO_SSL
105protected:
107 void ignoreSslErrorsImplementation(const QList<QSslError> &errors) override;
108 void setSslConfigurationImplementation(const QSslConfiguration &configuration) override;
109 void sslConfigurationImplementation(QSslConfiguration &configuration) const override;
110#endif
111
112signals:
113 // To HTTP thread:
116 void readBufferSizeChanged(qint64 size);
117 void readBufferFreed(qint64 size);
118
120
121 void haveUploadData(const qint64 pos, const QByteArray &dataArray, bool dataAtEnd, qint64 dataSize);
122};
123
125{
126public:
127
128 static QHttpNetworkRequest::Priority convert(QNetworkRequest::Priority prio);
129
132
133 void _q_startOperation();
134
136
139
141
142 void _q_transferTimedOut();
144
145 void _q_finished();
146
147 void finished();
148 void error(QNetworkReply::NetworkError code, const QString &errorString);
149 void _q_error(QNetworkReply::NetworkError code, const QString &errorString);
150 void _q_metaDataChanged();
151
152 void checkForRedirect(const int statusCode);
153
154 // incoming from user
157 QHttpNetworkRequest httpRequest; // There is also a copy in the HTTP thread
159
161
162 // from http thread
165
166 // upload
167 void maybeDropUploadDevice(const QNetworkRequest &newHttpRequest);
171 bool uploadDeviceChoking; // if we couldn't readPointer() any data at the moment
172 QIODevice *outgoingData;
174 void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); // dup?
175 void onRedirected(const QUrl &redirectUrl, int httpStatus, int maxRedirectsRemainig);
176 void followRedirect();
178
179
180 // cache
181 void createCache();
182 void completeCacheSave();
183 void setCachingEnabled(bool enable);
184 bool isCachingEnabled() const;
185 bool isCachingAllowed() const;
186 void initCacheSaveDevice();
187 QIODevice *cacheLoadDevice;
189
190 QIODevice *cacheSaveDevice;
191 bool cacheEnabled; // is this for saving?
192
193
195#ifndef QT_NO_NETWORKPROXY
197#endif
198
199
200 bool canResume() const;
201 void setResumeOffset(quint64 offset);
203
206 // We use this to keep track of whether or not we need to emit readyRead
207 // when we deal with signal compression (delaying emission) + decompressing
208 // data (potentially receiving bytes that don't end up in the final output):
210
212
213 // Only used when the "zero copy" style is used.
214 // Please note that the whole "zero copy" download buffer API is private right now. Do not use it.
219
220 // Will be increased by HTTP thread:
223
224
225#ifndef QT_NO_SSL
229#endif
230
232
234
235 bool loadFromCacheIfAllowed(QHttpNetworkRequest &httpRequest);
236 void invalidateCache();
237 bool sendCacheContents(const QNetworkCacheMetaData &metaData);
238 QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const;
239
240
241 void postRequest(const QNetworkRequest& newHttpRequest);
242 QNetworkAccessManager::Operation getRedirectOperation(QNetworkAccessManager::Operation currentOp, int httpStatus);
243 QNetworkRequest createRedirectRequest(const QNetworkRequest &originalRequests, const QUrl &url, int maxRedirectsRemainig);
244 bool isHttpRedirectResponse() const;
245
246public:
247 // From HTTP thread:
249 void replyFinished();
250 void replyDownloadMetaData(const QHttpHeaders &, int, const QString &,
251 bool, QSharedPointer<char>, qint64, qint64, bool, bool);
253 void httpAuthenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *auth);
254 void httpError(QNetworkReply::NetworkError error, const QString &errorString);
255#ifndef QT_NO_SSL
256 void replyEncrypted();
257 void replySslErrors(const QList<QSslError> &, bool *, QList<QSslError> *);
258 void replySslConfigurationChanged(const QSslConfiguration &newSslConfiguration);
260#endif
261#ifndef QT_NO_NETWORKPROXY
262 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
263#endif
264
265 // From QNonContiguousByteDeviceThreadForwardImpl in HTTP thread:
266 void resetUploadDataSlot(bool *r);
269
270 // From user's QNonContiguousByteDevice
272
273 Q_DECLARE_PUBLIC(QNetworkReplyHttpImpl)
274};
275
276QT_END_NAMESPACE
277
278#endif
\inmodule QtCore
Definition qatomic.h:113
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 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)