9#include "QtCore/qcoreapplication.h"
10#include "QtCore/qdatetime.h"
11#include "QtNetwork/qsslconfiguration.h"
14#include <QtCore/QCoreApplication>
21 : backend(
nullptr), outgoingData(
nullptr),
23 cacheEnabled(
false), cacheSaveDevice(
nullptr),
24 notificationHandlingPaused(
false),
25 bytesDownloaded(0), bytesUploaded(-1),
28 , downloadBufferReadPosition(0)
29 , downloadBufferCurrentSize(0)
30 , downloadBufferMaximumSize(0)
31 , downloadBuffer(
nullptr)
34 emitAllUploadProgressSignals =
true;
41 qDebug() <<
"QNetworkReplyImpl::_q_startOperation was called more than once" <<
url;
71 q_func()->setFinished(
true);
102 if (bytesActuallyRead == -1) {
106 buffer.chop(bytesToRead - bytesActuallyRead);
176 if (bytesToBuffer <= 0)
177 bytesToBuffer = 2*1024;
182 if (bytesBuffered == -1) {
188 }
else if (bytesBuffered == 0) {
218 if (synchronousHttpAttribute.toBool() &&
outgoingData) {
220 qint64 previousDataSize = 0;
228 backend->setSynchronous(synchronousHttpAttribute.toBool());
240 bool bufferingDisallowed =
244 if (bufferingDisallowed) {
291 switch (notification) {
353 qCritical(
"QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written");
361 qDebug(
"QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false) -- "
362 "backend %s probably needs to be fixed",
363 backend->metaObject()->className());
399 emit q->uploadProgress(bytesSent, bytesTotal);
406 enum { DesiredBufferSize = 32 * 1024 };
408 return DesiredBufferSize;
432 if (redirectionTarget.isValid()) {
442 qCritical(
"QNetworkReplyImpl: network cache returned a device that is not open -- "
443 "class %s probably needs to be fixed",
513 qCritical(
"QNetworkReplyImpl: copy from QIODevice already in progress -- "
514 "backend probably needs to be fixed");
534 if (bufferAllocationPolicy.isValid() && bufferAllocationPolicy.toLongLong() >=
size) {
598 const auto totalSize = totalSizeOpt.value_or(-1);
603 q->setFinished(
true);
608 if (totalSize == -1) {
615 emit q->uploadProgress(0, 0);
626 emit q->readChannelFinished();
636 qWarning(
"QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.");
646 emit q->errorOccurred(code);
657 const auto cookies = cookiesOpt.value_or(QList<QNetworkCookie>());
668 emit q->metaDataChanged();
688 emit q->sslErrors(errors);
704 bool anyBytesRead =
false;
713 buffer.chop(toRead - bytesRead);
714 anyBytesRead |= bytesRead > 0;
733 if (
d->isCachingEnabled())
734 d->networkCache()->remove(
url());
745 disconnect(
d->outgoingData,
nullptr,
this,
nullptr);
758 d->backend->deleteLater();
759 d->backend =
nullptr;
792 if (
d->downloadBuffer) {
793 qint64 maxAvail =
d->downloadBufferCurrentSize -
d->downloadBufferReadPosition;
802 qint64 oldMaxSize =
d->readBufferMaxSize;
804 if (
size > oldMaxSize &&
size >
d->buffer.size())
805 d->readFromBackend();
809void QNetworkReplyImpl::sslConfigurationImplementation(
QSslConfiguration &configuration)
const
813 configuration =
d->backend->sslConfiguration();
819 if (
d->backend && !
config.isNull())
820 d->backend->setSslConfiguration(
config);
827 d->backend->ignoreSslErrors();
834 d->backend->ignoreSslErrors(errors);
848 while (
d->backend->bytesAvailable()) {
852 memcpy(
data + bytesRead,
view.data(), bytesToCopy);
855 if (
d->cacheEnabled && !
d->cacheSaveDevice)
856 d->initCacheSaveDevice();
857 if (
d->cacheEnabled &&
d->cacheSaveDevice)
858 d->cacheSaveDevice->write(
view.data(),
view.size());
860 bytesRead += bytesToCopy;
861 d->backend->advanceReadPointer(bytesToCopy);
871 }
else if (
d->backend &&
d->backend->bytesAvailable()) {
872 return d->backend->read(
data, maxlen);
876 if (
d->downloadBuffer) {
877 qint64 maxAvail = qMin<qint64>(
d->downloadBufferCurrentSize -
d->downloadBufferReadPosition, maxlen);
881 memcpy(
data,
d->downloadBuffer +
d->downloadBufferReadPosition, maxAvail);
882 d->downloadBufferReadPosition += maxAvail;
901 d_func()->handleNotifications();
910#include "moc_qnetworkreplyimpl_p.cpp"
The QAbstractNetworkCache class provides the interface for cache implementations.
virtual void insert(QIODevice *device)=0
Inserts the data in device and the prepared meta data into the cache.
virtual QIODevice * prepare(const QNetworkCacheMetaData &metaData)=0
Returns the device that should be populated with the data for the cache item metaData.
virtual bool remove(const QUrl &url)=0
Removes the cache entry for url, returning true if success otherwise false.
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
void invalidate() noexcept
Marks this QElapsedTimer object as invalid.
qint64 elapsed() const noexcept
Returns the number of milliseconds since this QElapsedTimer was last started.
qint64 restart() noexcept
Restarts the timer and returns the number of milliseconds elapsed since the previous start.
void start() noexcept
\typealias QElapsedTimer::Duration Synonym for std::chrono::nanoseconds.
bool isValid() const noexcept
Returns false if the timer has never been started or invalidated by a call to invalidate().
Type type() const
Returns the event type.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
\inmodule QtCore \reentrant
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i....
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
virtual qint64 read(char *data, qint64 maxlen)
Implement this function to support reading from the resource made available by your plugin.
virtual bool start()
Prepares the backend and calls open().
bool needsResetableUploadData() const noexcept
virtual bool wantToRead()
This is called before we read if there are no bytes available and we are ready to read more.
virtual qint64 bytesAvailable() const =0
You must implement this function in your derived class.
QAbstractNetworkCache * networkCache() const
Returns the network cache object that was available when the request was started.
IOFeatures ioFeatures() const noexcept
Returns the I/O features that the backend claims to support.
Operation
Indicates the operation this reply is processing.
QNetworkCookieJar * cookieJar() const
Returns the QNetworkCookieJar that is used to store cookies obtained from the network as well as cook...
The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects.
virtual bool setCookiesFromUrl(const QList< QNetworkCookie > &cookieList, const QUrl &url)
Adds the cookies in the list cookieList to this cookie jar.
void handleNotifications()
void resumeNotificationHandling()
void _q_bufferOutgoingDataFinished()
qint64 downloadBufferMaximumSize
@ NotifyDownstreamReadyWrite
std::vector< InternalNotifications > pendingNotifications
qint64 nextDownstreamBlockSize() const
void setDownloadBuffer(QSharedPointer< char > sp, qint64 size)
void error(QNetworkReply::NetworkError code, const QString &errorString)
void appendDownstreamDataDownloadBuffer(qint64, qint64)
QSharedPointer< char > downloadBufferPointer
QNetworkAccessBackend * backend
void _q_bufferOutgoingData()
bool notificationHandlingPaused
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
void emitUploadProgress(qint64 bytesSent, qint64 bytesTotal)
qint64 downloadBufferCurrentSize
void backendNotify(InternalNotifications notification)
void appendDownstreamDataSignalEmissions()
std::shared_ptr< QRingBuffer > outgoingDataBuffer
void initCacheSaveDevice()
QAbstractNetworkCache * networkCache() const
void appendDownstreamData(QByteDataBuffer &data)
char * getDownloadBuffer(qint64 size)
void _q_copyReadChannelFinished()
bool isCachingEnabled() const
void sslErrors(const QList< QSslError > &errors)
void pauseNotificationHandling()
QIODevice * cacheSaveDevice
void redirectionRequested(const QUrl &target)
void setCachingEnabled(bool enable)
virtual qint64 bytesAvailable() const override
Returns the number of bytes available for reading with QIODevice::read().
virtual qint64 readData(char *data, qint64 maxlen) override
QNetworkReplyImpl(QObject *parent=nullptr)
virtual void ignoreSslErrorsImplementation(const QList< QSslError > &errors) override
virtual void setReadBufferSize(qint64 size) override
Sets the size of the read buffer to be size bytes.
virtual void close() override
Closes this device for reading.
virtual void abort() override
Aborts the operation immediately and close down any network connections still open.
virtual bool event(QEvent *) override
void void void void _q_bufferOutgoingDataFinished()) protected void setSslConfigurationImplementation(const QSslConfiguration &configuration) override
virtual void ignoreSslErrors() override
If this function is called, SSL errors related to network connection will be ignored,...
QPointer< QNetworkAccessManager > manager
QElapsedTimer downloadProgressSignalChoke
static const int progressSignalInterval
QNetworkAccessManager::Operation operation
QNetworkRequest originalRequest
bool emitAllUploadProgressSignals
QElapsedTimer uploadProgressSignalChoke
QNetworkReply::NetworkError errorCode
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
virtual void setReadBufferSize(qint64 size)
Sets the size of the read buffer to be size bytes.
virtual void close() override
Closes this device for reading.
QHttpHeaders headers() const
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
This signal is emitted to indicate the progress of the download part of this network request,...
NetworkError
Indicates all possible error conditions found during the processing of the request.
QUrl url() const
Returns the URL of the content downloaded or uploaded.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
@ EmitAllUploadProgressSignalsAttribute
@ CookieSaveControlAttribute
@ HttpStatusCodeAttribute
@ CacheSaveControlAttribute
@ DownloadBufferAttribute
@ DoNotBufferUploadDataAttribute
@ RedirectionTargetAttribute
@ MaximumDownloadBufferSizeAttribute
@ SynchronousRequestAttribute
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
QUrl url() const
Returns the URL this network request is referring to.
QDynamicMetaObjectData * metaObject
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
bool isNull() const noexcept
const_iterator cend() const noexcept
T * data() const noexcept
Returns the value of the pointer referenced by this object.
The QSslConfiguration class holds the configuration and state of an SSL connection.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString scheme() const
Returns the scheme of the URL.
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
QSet< QString >::iterator it
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
GLenum GLsizei GLuint GLint * bytesWritten
GLenum GLsizei GLsizei GLint * values
[15]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)
const char className[16]
[1]
myObject disconnect()
[26]
QNetworkRequest request(url)