Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qnetworkreply.cpp
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
4#include <QtNetwork/private/qtnetworkglobal_p.h>
5
6#include "qnetworkreply.h"
7#include "qnetworkreply_p.h"
8#include <QtNetwork/qsslconfiguration.h>
9
11
13
15
17 : readBufferMaxSize(0),
18 emitAllUploadProgressSignals(false),
19 operation(QNetworkAccessManager::UnknownOperation),
20 errorCode(QNetworkReply::NoError)
21 , isFinished(false)
22{
23 // set the default attribute values
25}
26
27
439
444 : QIODevice(dd, parent)
445{
446}
447
458
474
479{
480 return true;
481}
482
489{
490 return d_func()->readBufferMaxSize;
491}
492
512{
513 Q_D(QNetworkReply);
514 d->readBufferMaxSize = size;
515}
516
522{
523 return d_func()->manager;
524}
525
534{
535 return d_func()->originalRequest;
536}
537
544{
545 return d_func()->operation;
546}
547
555{
556 return d_func()->errorCode;
557}
558
567{
568 return d_func()->isFinished;
569}
570
580{
581 return !isFinished();
582}
583
594{
595 return d_func()->url;
596}
597
606{
607 return d_func()->cookedHeaders.value(header);
608}
609
618{
619 Q_D(const QNetworkReply);
620 return d->headers().contains(headerName);
621}
622
634{
635 Q_D(const QNetworkReply);
636 return d->rawHeader(headerName);
637}
638
648const QList<QNetworkReply::RawHeaderPair>& QNetworkReply::rawHeaderPairs() const
649{
650 Q_D(const QNetworkReply);
651 return d->allRawHeaders();
652}
653
662{
663 Q_D(const QNetworkReply);
664 return d->headers();
665}
666
672QList<QByteArray> QNetworkReply::rawHeaderList() const
673{
674 return d_func()->rawHeadersKeys();
675}
676
688{
689 return d_func()->attributes.value(code);
690}
691
692#if QT_CONFIG(ssl)
702QSslConfiguration QNetworkReply::sslConfiguration() const
703{
705 sslConfigurationImplementation(config);
706 return config;
707}
708
713void QNetworkReply::setSslConfiguration(const QSslConfiguration &config)
714{
715 setSslConfigurationImplementation(config);
716}
717
743void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)
744{
745 ignoreSslErrorsImplementation(errors);
746}
747
758void QNetworkReply::sslConfigurationImplementation(QSslConfiguration &) const
759{
760}
761
772void QNetworkReply::setSslConfigurationImplementation(const QSslConfiguration &)
773{
774}
775
786void QNetworkReply::ignoreSslErrorsImplementation(const QList<QSslError> &)
787{
788}
789
790#endif // QT_CONFIG(ssl)
791
817
822{
823 return -1; // you can't write
824}
825
836{
837 Q_D(QNetworkReply);
838 d->operation = operation;
839}
840
851{
852 Q_D(QNetworkReply);
853 d->originalRequest = request;
854}
855
865void QNetworkReply::setError(NetworkError errorCode, const QString &errorString)
866{
867 Q_D(QNetworkReply);
868 d->errorCode = errorCode;
869 setErrorString(errorString); // in QIODevice
870}
871
880void QNetworkReply::setFinished(bool finished)
881{
882 Q_D(QNetworkReply);
883 d->isFinished = finished;
884}
885
886
896{
897 Q_D(QNetworkReply);
898 d->url = url;
899}
900
913{
914 Q_D(QNetworkReply);
915 d->setHeaders(newHeaders);
916}
917
923{
924 Q_D(QNetworkReply);
925 d->setHeaders(std::move(newHeaders));
926}
927
939
951
964{
965 Q_D(QNetworkReply);
966 d->setRawHeader(headerName, value);
967}
968
977{
978 Q_D(QNetworkReply);
979 if (value.isValid())
980 d->attributes.insert(code, value);
981 else
982 d->attributes.remove(code);
983}
984
986
987#include "moc_qnetworkreply.cpp"
\inmodule QtCore
\inmodule QtCore
Definition qbytearray.h:57
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1303
WellKnownHeader
List of well known headers as per \l {https://www.iana.org/assignments/http-fields}{IANA registry}.
\inmodule QtCore \reentrant
Definition qiodevice.h:34
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
void setErrorString(const QString &errorString)
Sets the human readable description of the last device error that occurred to str.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
The QNetworkAccessManager class allows the application to send network requests and receive replies.
Operation
Indicates the operation this reply is processing.
static const int progressSignalInterval
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.
QNetworkAccessManager * manager() const
Returns the QNetworkAccessManager that was used to create this QNetworkReply object.
bool hasRawHeader(QAnyStringView headerName) const
Returns true if the raw header of name headerName was sent by the remote server.
QByteArray rawHeader(QAnyStringView headerName) const
Returns the raw contents of the header headerName as sent by the remote server.
void setError(NetworkError errorCode, const QString &errorString)
Sets the error condition to be errorCode.
bool isFinished() const
virtual void close() override
Closes this device for reading.
QNetworkAccessManager::Operation operation() const
Returns the operation that was posted for this reply.
void setWellKnownHeader(QHttpHeaders::WellKnownHeader name, const QByteArray &value)
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
qint64 readBufferSize() const
Returns the size of the read buffer, in bytes.
virtual bool isSequential() const override
QHttpHeaders headers() const
void setOperation(QNetworkAccessManager::Operation operation)
Sets the associated operation for this object to be operation.
bool isRunning() const
void setUrl(const QUrl &url)
Sets the URL being processed to be url.
NetworkError error() const
Returns the error that was found during the processing of this request.
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the raw header headerName to be of value value.
void setHeaders(const QHttpHeaders &newHeaders)
QNetworkReply(QObject *parent=nullptr)
Creates a QNetworkReply object with parent parent.
void setAttribute(QNetworkRequest::Attribute code, const QVariant &value)
Sets the attribute code to have value value.
QVariant header(QNetworkRequest::KnownHeaders header) const
Returns the value of the known header header, if that header was sent by the remote server.
void setRequest(const QNetworkRequest &request)
Sets the associated request for this object to be request.
NetworkError
Indicates all possible error conditions found during the processing of the request.
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
Sets the known header header to be of value value.
void setFinished(bool)
virtual void ignoreSslErrors()
If this function is called, SSL errors related to network connection will be ignored,...
QList< QByteArray > rawHeaderList() const
Returns a list of headers fields that were sent by the remote server, in the order that they were sen...
void finished()
This signal is emitted when the reply has finished processing.
QNetworkRequest request() const
Returns the request that was posted for this reply.
virtual qint64 writeData(const char *data, qint64 len) override
~QNetworkReply()
Disposes of this reply and frees any resources associated with it.
QUrl url() const
Returns the URL of the content downloaded or uploaded.
const QList< RawHeaderPair > & rawHeaderPairs() const
Returns a list of raw header pairs.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
KnownHeaders
List of known header types that QNetworkRequest parses.
\inmodule QtCore
Definition qobject.h:103
The QSslConfiguration class holds the configuration and state of an SSL connection.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
QString url(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2817
\inmodule QtCore
Definition qvariant.h:65
T value() const &
Definition qvariant.h:516
Combined button and popup list for selecting options.
static QString header(const QString &name)
EGLConfig config
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
Definition qmetatype.h:1384
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint name
@ NoError
Definition main.cpp:34
long long qint64
Definition qtypes.h:60
QUrl url("example.com")
[constructor-url-reference]
QNetworkRequest request(url)