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);
175 if (bytesToBuffer <= 0)
176 bytesToBuffer = 2*1024;
181 if (bytesBuffered == -1) {
187 }
else if (bytesBuffered == 0) {
219 qint64 previousDataSize = 0;
239 bool bufferingDisallowed =
243 if (bufferingDisallowed) {
287 switch (notification) {
349 qCritical(
"QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written");
357 qDebug(
"QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false) -- "
358 "backend %s probably needs to be fixed",
359 backend->metaObject()->className());
395 emit q->uploadProgress(bytesSent, bytesTotal);
402 enum { DesiredBufferSize = 32 * 1024 };
404 return DesiredBufferSize;
428 if (redirectionTarget.
isValid()) {
438 qCritical(
"QNetworkReplyImpl: network cache returned a device that is not open -- "
439 "class %s probably needs to be fixed",
509 qCritical(
"QNetworkReplyImpl: copy from QIODevice already in progress -- "
510 "backend probably needs to be fixed");
597 q->setFinished(
true);
602 if (totalSize.
isNull() || totalSize == -1) {
609 emit q->uploadProgress(0, 0);
620 emit q->readChannelFinished();
630 qWarning(
"QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.");
640 emit q->errorOccurred(code);
656 qvariant_cast<QList<QNetworkCookie> >(
it.value());
662 emit q->metaDataChanged();
682 emit q->sslErrors(errors);
698 bool anyBytesRead =
false;
707 buffer.chop(toRead - bytesRead);
708 anyBytesRead |= bytesRead > 0;
727 if (
d->isCachingEnabled())
728 d->networkCache()->remove(
url());
739 disconnect(
d->outgoingData,
nullptr,
this,
nullptr);
752 d->backend->deleteLater();
753 d->backend =
nullptr;
786 if (
d->downloadBuffer) {
787 qint64 maxAvail =
d->downloadBufferCurrentSize -
d->downloadBufferReadPosition;
796 qint64 oldMaxSize =
d->readBufferMaxSize;
798 if (
size > oldMaxSize &&
size >
d->buffer.size())
799 d->readFromBackend();
803void QNetworkReplyImpl::sslConfigurationImplementation(
QSslConfiguration &configuration)
const
807 configuration =
d->backend->sslConfiguration();
813 if (
d->backend && !
config.isNull())
814 d->backend->setSslConfiguration(
config);
821 d->backend->ignoreSslErrors();
828 d->backend->ignoreSslErrors(errors);
842 while (
d->backend->bytesAvailable()) {
846 memcpy(
data + bytesRead,
view.data(), bytesToCopy);
849 if (
d->cacheEnabled && !
d->cacheSaveDevice)
850 d->initCacheSaveDevice();
851 if (
d->cacheEnabled &&
d->cacheSaveDevice)
852 d->cacheSaveDevice->write(
view.data(),
view.size());
854 bytesRead += bytesToCopy;
855 d->backend->advanceReadPointer(bytesToCopy);
864 }
else if (
d->backend &&
d->backend->bytesAvailable()) {
865 return d->backend->read(
data, maxlen);
869 if (
d->downloadBuffer) {
870 qint64 maxAvail = qMin<qint64>(
d->downloadBufferCurrentSize -
d->downloadBufferReadPosition, maxlen);
874 memcpy(
data,
d->downloadBuffer +
d->downloadBufferReadPosition, maxAvail);
875 d->downloadBufferReadPosition += maxAvail;
894 d_func()->handleNotifications();
903#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
Starts this timer.
bool isValid() const noexcept
Returns false if the timer has never been started or invalidated by a call to invalidate().
const_iterator constFind(const Key &key) const noexcept
T value(const Key &key) const noexcept
const_iterator cend() const noexcept
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.
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.
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
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
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
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.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
qlonglong toLongLong(bool *ok=nullptr) const
Returns the variant as a long long int if the variant has userType() \l QMetaType::LongLong,...
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.
bool isNull() const
Returns true if this is a null variant, false otherwise.
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
constexpr const T & qMin(const T &a, const T &b)
GLenum GLsizei GLuint GLint * bytesWritten
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)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent