1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtNetwork module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include <QtNetwork/private/qtnetworkglobal_p.h>
41
42#include "qnetworkreply.h"
43#include "qnetworkreply_p.h"
44#include <QtNetwork/qsslconfiguration.h>
45
46QT_BEGIN_NAMESPACE
47
48const int QNetworkReplyPrivate::progressSignalInterval = 100;
49
50QNetworkReplyPrivate::QNetworkReplyPrivate()
51 : readBufferMaxSize(0),
52 emitAllUploadProgressSignals(false),
53 operation(QNetworkAccessManager::UnknownOperation),
54 errorCode(QNetworkReply::NoError)
55 , isFinished(false)
56{
57 // set the default attribute values
58 attributes.insert(akey: QNetworkRequest::ConnectionEncryptedAttribute, avalue: false);
59}
60
61
62/*!
63 \class QNetworkReply
64 \since 4.4
65 \brief The QNetworkReply class contains the data and headers for a request
66 sent with QNetworkAccessManager.
67
68 \reentrant
69 \ingroup network
70 \inmodule QtNetwork
71
72 The QNetworkReply class contains the data and meta data related to
73 a request posted with QNetworkAccessManager. Like QNetworkRequest,
74 it contains a URL and headers (both in parsed and raw form), some
75 information about the reply's state and the contents of the reply
76 itself.
77
78 QNetworkReply is a sequential-access QIODevice, which means that
79 once data is read from the object, it no longer kept by the
80 device. It is therefore the application's responsibility to keep
81 this data if it needs to. Whenever more data is received from the
82 network and processed, the readyRead() signal is emitted.
83
84 The downloadProgress() signal is also emitted when data is
85 received, but the number of bytes contained in it may not
86 represent the actual bytes received, if any transformation is done
87 to the contents (for example, decompressing and removing the
88 protocol overhead).
89
90 Even though QNetworkReply is a QIODevice connected to the contents
91 of the reply, it also emits the uploadProgress() signal, which
92 indicates the progress of the upload for operations that have such
93 content.
94
95 \note Do not delete the object in the slot connected to the
96 errorOccurred() or finished() signal. Use deleteLater().
97
98 \sa QNetworkRequest, QNetworkAccessManager
99*/
100
101/*!
102 \enum QNetworkReply::NetworkError
103
104 Indicates all possible error conditions found during the
105 processing of the request.
106
107 \value NoError no error condition.
108 \note When the HTTP protocol returns a redirect no error will be
109 reported. You can check if there is a redirect with the
110 QNetworkRequest::RedirectionTargetAttribute attribute.
111
112 \value ConnectionRefusedError the remote server refused the
113 connection (the server is not accepting requests)
114
115 \value RemoteHostClosedError the remote server closed the
116 connection prematurely, before the entire reply was received and
117 processed
118
119 \value HostNotFoundError the remote host name was not found
120 (invalid hostname)
121
122 \value TimeoutError the connection to the remote server
123 timed out
124
125 \value OperationCanceledError the operation was canceled via calls
126 to abort() or close() before it was finished.
127
128 \value SslHandshakeFailedError the SSL/TLS handshake failed and the
129 encrypted channel could not be established. The sslErrors() signal
130 should have been emitted.
131
132 \value TemporaryNetworkFailureError the connection was broken due
133 to disconnection from the network, however the system has initiated
134 roaming to another access point. The request should be resubmitted
135 and will be processed as soon as the connection is re-established.
136
137 \value NetworkSessionFailedError the connection was broken due
138 to disconnection from the network or failure to start the network.
139
140 \value BackgroundRequestNotAllowedError the background request
141 is not currently allowed due to platform policy.
142
143 \value TooManyRedirectsError while following redirects, the maximum
144 limit was reached. The limit is by default set to 50 or as set by
145 QNetworkRequest::setMaxRedirectsAllowed().
146 (This value was introduced in 5.6.)
147
148 \value InsecureRedirectError while following redirects, the network
149 access API detected a redirect from a encrypted protocol (https) to an
150 unencrypted one (http).
151 (This value was introduced in 5.6.)
152
153 \value ProxyConnectionRefusedError the connection to the proxy
154 server was refused (the proxy server is not accepting requests)
155
156 \value ProxyConnectionClosedError the proxy server closed the
157 connection prematurely, before the entire reply was received and
158 processed
159
160 \value ProxyNotFoundError the proxy host name was not
161 found (invalid proxy hostname)
162
163 \value ProxyTimeoutError the connection to the proxy
164 timed out or the proxy did not reply in time to the request sent
165
166 \value ProxyAuthenticationRequiredError the proxy requires
167 authentication in order to honour the request but did not accept
168 any credentials offered (if any)
169
170 \value ContentAccessDenied the access to the remote
171 content was denied (similar to HTTP error 403)
172
173 \value ContentOperationNotPermittedError the operation requested
174 on the remote content is not permitted
175
176 \value ContentNotFoundError the remote content was not
177 found at the server (similar to HTTP error 404)
178
179 \value AuthenticationRequiredError the remote server requires
180 authentication to serve the content but the credentials provided
181 were not accepted (if any)
182
183 \value ContentReSendError the request needed to be sent
184 again, but this failed for example because the upload data
185 could not be read a second time.
186
187 \value ContentConflictError the request could not be completed due
188 to a conflict with the current state of the resource.
189
190 \value ContentGoneError the requested resource is no longer
191 available at the server.
192
193 \value InternalServerError the server encountered an unexpected
194 condition which prevented it from fulfilling the request.
195
196 \value OperationNotImplementedError the server does not support the
197 functionality required to fulfill the request.
198
199 \value ServiceUnavailableError the server is unable to handle the
200 request at this time.
201
202 \value ProtocolUnknownError the Network Access API cannot
203 honor the request because the protocol is not known
204
205 \value ProtocolInvalidOperationError the requested operation is
206 invalid for this protocol
207
208 \value UnknownNetworkError an unknown network-related
209 error was detected
210
211 \value UnknownProxyError an unknown proxy-related error
212 was detected
213
214 \value UnknownContentError an unknown error related to
215 the remote content was detected
216
217 \value ProtocolFailure a breakdown in protocol was
218 detected (parsing error, invalid or unexpected responses, etc.)
219
220 \value UnknownServerError an unknown error related to
221 the server response was detected
222
223 \sa error()
224 \sa errorOccurred()
225*/
226
227/*!
228 \fn void QNetworkReply::encrypted()
229 \since 5.1
230
231 This signal is emitted when an SSL/TLS session has successfully
232 completed the initial handshake. At this point, no user data
233 has been transmitted. The signal can be used to perform
234 additional checks on the certificate chain, for example to
235 notify users when the certificate for a website has changed.
236 If the reply does not match the expected criteria then it should
237 be aborted by calling QNetworkReply::abort() by a slot connected
238 to this signal. The SSL configuration in use can be inspected
239 using the QNetworkReply::sslConfiguration() method.
240
241 Internally, QNetworkAccessManager may open multiple connections
242 to a server, in order to allow it process requests in parallel.
243 These connections may be reused, which means that the encrypted()
244 signal would not be emitted. This means that you are only
245 guaranteed to receive this signal for the first connection to a
246 site in the lifespan of the QNetworkAccessManager.
247
248 \sa QSslSocket::encrypted()
249 \sa QNetworkAccessManager::encrypted()
250*/
251
252/*!
253 \fn void QNetworkReply::sslErrors(const QList<QSslError> &errors)
254
255 This signal is emitted if the SSL/TLS session encountered errors
256 during the set up, including certificate verification errors. The
257 \a errors parameter contains the list of errors.
258
259 To indicate that the errors are not fatal and that the connection
260 should proceed, the ignoreSslErrors() function should be called
261 from the slot connected to this signal. If it is not called, the
262 SSL session will be torn down before any data is exchanged
263 (including the URL).
264
265 This signal can be used to display an error message to the user
266 indicating that security may be compromised and display the
267 SSL settings (see sslConfiguration() to obtain it). If the user
268 decides to proceed after analyzing the remote certificate, the
269 slot should call ignoreSslErrors().
270
271 \sa QSslSocket::sslErrors(), QNetworkAccessManager::sslErrors(),
272 sslConfiguration(), ignoreSslErrors()
273*/
274
275/*!
276 \fn void QNetworkReply::preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator)
277 \since 5.5
278
279 This signal is emitted if the SSL/TLS handshake negotiates a PSK
280 ciphersuite, and therefore a PSK authentication is then required.
281
282 When using PSK, the client must send to the server a valid identity and a
283 valid pre shared key, in order for the SSL handshake to continue.
284 Applications can provide this information in a slot connected to this
285 signal, by filling in the passed \a authenticator object according to their
286 needs.
287
288 \note Ignoring this signal, or failing to provide the required credentials,
289 will cause the handshake to fail, and therefore the connection to be aborted.
290
291 \note The \a authenticator object is owned by the reply and must not be
292 deleted by the application.
293
294 \sa QSslPreSharedKeyAuthenticator
295*/
296
297/*!
298 \fn void QNetworkReply::redirected(const QUrl &url)
299 \since 5.6
300
301 This signal is emitted if the QNetworkRequest::FollowRedirectsAttribute was
302 set in the request and the server responded with a 3xx status (specifically
303 301, 302, 303, 305, 307 or 308 status code) with a valid url in the location
304 header, indicating a HTTP redirect. The \a url parameter contains the new
305 redirect url as returned by the server in the location header.
306
307 \sa QNetworkRequest::FollowRedirectsAttribute
308*/
309
310/*!
311 \fn void QNetworkReply::redirectAllowed()
312 \since 5.9
313
314 When client code handling the redirected() signal has verified the new URL,
315 it emits this signal to allow the redirect to go ahead. This protocol applies
316 to network requests whose redirects policy is set to
317 QNetworkRequest::UserVerifiedRedirectPolicy
318
319 \sa QNetworkRequest::UserVerifiedRedirectPolicy,
320 QNetworkAccessManager::setRedirectPolicy(),
321 QNetworkRequest::RedirectPolicyAttribute
322*/
323
324/*!
325 \fn void QNetworkReply::metaDataChanged()
326
327 \omit FIXME: Update name? \endomit
328
329 This signal is emitted whenever the metadata in this reply
330 changes. metadata is any information that is not the content
331 (data) itself, including the network headers. In the majority of
332 cases, the metadata will be known fully by the time the first
333 byte of data is received. However, it is possible to receive
334 updates of headers or other metadata during the processing of the
335 data.
336
337 \sa header(), rawHeaderList(), rawHeader(), hasRawHeader()
338*/
339
340/*!
341 \fn void QNetworkReply::finished()
342
343 This signal is emitted when the reply has finished
344 processing. After this signal is emitted, there will be no more
345 updates to the reply's data or metadata.
346
347 Unless close() or abort() have been called, the reply will be still be opened
348 for reading, so the data can be retrieved by calls to read() or
349 readAll(). In particular, if no calls to read() were made as a
350 result of readyRead(), a call to readAll() will retrieve the full
351 contents in a QByteArray.
352
353 This signal is emitted in tandem with
354 QNetworkAccessManager::finished() where that signal's reply
355 parameter is this object.
356
357 \note Do not delete the object in the slot connected to this
358 signal. Use deleteLater().
359
360 You can also use isFinished() to check if a QNetworkReply
361 has finished even before you receive the finished() signal.
362
363 \sa QNetworkAccessManager::finished(), isFinished()
364*/
365
366/*!
367 \fn void QNetworkReply::error(QNetworkReply::NetworkError code)
368 \obsolete
369
370 Use errorOccurred() instead.
371*/
372
373/*!
374 \fn void QNetworkReply::errorOccurred(QNetworkReply::NetworkError code)
375 \since 5.15
376
377 This signal is emitted when the reply detects an error in
378 processing. The finished() signal will probably follow, indicating
379 that the connection is over.
380
381 The \a code parameter contains the code of the error that was
382 detected. Call errorString() to obtain a textual representation of
383 the error condition.
384
385 \note Do not delete the object in the slot connected to this
386 signal. Use deleteLater().
387
388 \sa error(), errorString()
389*/
390
391/*!
392 \fn void QNetworkReply::uploadProgress(qint64 bytesSent, qint64 bytesTotal)
393
394 This signal is emitted to indicate the progress of the upload part
395 of this network request, if there's any. If there's no upload
396 associated with this request, this signal will not be emitted.
397
398 The \a bytesSent
399 parameter indicates the number of bytes uploaded, while \a
400 bytesTotal indicates the total number of bytes to be uploaded. If
401 the number of bytes to be uploaded could not be determined, \a
402 bytesTotal will be -1.
403
404 The upload is finished when \a bytesSent is equal to \a
405 bytesTotal. At that time, \a bytesTotal will not be -1.
406
407 \sa downloadProgress()
408*/
409
410/*!
411 \fn void QNetworkReply::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
412
413 This signal is emitted to indicate the progress of the download
414 part of this network request, if there's any. If there's no
415 download associated with this request, this signal will be emitted
416 once with 0 as the value of both \a bytesReceived and \a
417 bytesTotal.
418
419 The \a bytesReceived parameter indicates the number of bytes
420 received, while \a bytesTotal indicates the total number of bytes
421 expected to be downloaded. If the number of bytes to be downloaded
422 is not known, \a bytesTotal will be -1.
423
424 The download is finished when \a bytesReceived is equal to \a
425 bytesTotal. At that time, \a bytesTotal will not be -1.
426
427 Note that the values of both \a bytesReceived and \a bytesTotal
428 may be different from size(), the total number of bytes
429 obtained through read() or readAll(), or the value of the
430 header(ContentLengthHeader). The reason for that is that there may
431 be protocol overhead or the data may be compressed during the
432 download.
433
434 \sa uploadProgress(), bytesAvailable()
435*/
436
437/*!
438 \fn void QNetworkReply::abort()
439
440 Aborts the operation immediately and close down any network
441 connections still open. Uploads still in progress are also
442 aborted.
443
444 The finished() signal will also be emitted.
445
446 \sa close(), finished()
447*/
448
449/*!
450 Creates a QNetworkReply object with parent \a parent.
451
452 You cannot directly instantiate QNetworkReply objects. Use
453 QNetworkAccessManager functions to do that.
454*/
455QNetworkReply::QNetworkReply(QObject *parent)
456 : QNetworkReply(*new QNetworkReplyPrivate, parent)
457{
458}
459
460/*!
461 \internal
462*/
463QNetworkReply::QNetworkReply(QNetworkReplyPrivate &dd, QObject *parent)
464 : QIODevice(dd, parent)
465{
466 // Support the deprecated error() signal:
467 connect(sender: this, signal: &QNetworkReply::errorOccurred, receiver: this, slot: QOverload<QNetworkReply::NetworkError>::of(ptr: &QNetworkReply::error));
468}
469
470/*!
471 Disposes of this reply and frees any resources associated with
472 it. If any network connections are still open, they will be
473 closed.
474
475 \sa abort(), close()
476*/
477QNetworkReply::~QNetworkReply()
478{
479}
480
481/*!
482 Closes this device for reading. Unread data is discarded, but the
483 network resources are not discarded until they are finished. In
484 particular, if any upload is in progress, it will continue until
485 it is done.
486
487 The finished() signal is emitted when all operations are over and
488 the network resources are freed.
489
490 \sa abort(), finished()
491*/
492void QNetworkReply::close()
493{
494 QIODevice::close();
495}
496
497/*!
498 \internal
499*/
500bool QNetworkReply::isSequential() const
501{
502 return true;
503}
504
505/*!
506 Returns the size of the read buffer, in bytes.
507
508 \sa setReadBufferSize()
509*/
510qint64 QNetworkReply::readBufferSize() const
511{
512 return d_func()->readBufferMaxSize;
513}
514
515/*!
516 Sets the size of the read buffer to be \a size bytes. The read
517 buffer is the buffer that holds data that is being downloaded off
518 the network, before it is read with QIODevice::read(). Setting the
519 buffer size to 0 will make the buffer unlimited in size.
520
521 QNetworkReply will try to stop reading from the network once this
522 buffer is full (i.e., bytesAvailable() returns \a size or more),
523 thus causing the download to throttle down as well. If the buffer
524 is not limited in size, QNetworkReply will try to download as fast
525 as possible from the network.
526
527 Unlike QAbstractSocket::setReadBufferSize(), QNetworkReply cannot
528 guarantee precision in the read buffer size. That is,
529 bytesAvailable() can return more than \a size.
530
531 \sa readBufferSize()
532*/
533void QNetworkReply::setReadBufferSize(qint64 size)
534{
535 Q_D(QNetworkReply);
536 d->readBufferMaxSize = size;
537}
538
539/*!
540 Returns the QNetworkAccessManager that was used to create this
541 QNetworkReply object. Initially, it is also the parent object.
542*/
543QNetworkAccessManager *QNetworkReply::manager() const
544{
545 return d_func()->manager;
546}
547
548/*!
549 Returns the request that was posted for this reply. In special,
550 note that the URL for the request may be different than that of
551 the reply.
552
553 \sa QNetworkRequest::url(), url(), setRequest()
554*/
555QNetworkRequest QNetworkReply::request() const
556{
557 return d_func()->originalRequest;
558}
559
560/*!
561 Returns the operation that was posted for this reply.
562
563 \sa setOperation()
564*/
565QNetworkAccessManager::Operation QNetworkReply::operation() const
566{
567 return d_func()->operation;
568}
569
570/*!
571 Returns the error that was found during the processing of this
572 request. If no error was found, returns NoError.
573
574 \sa setError()
575*/
576QNetworkReply::NetworkError QNetworkReply::error() const
577{
578 return d_func()->errorCode;
579}
580
581/*!
582 \since 4.6
583
584 Returns \c true when the reply has finished or was aborted.
585
586 \sa isRunning()
587*/
588bool QNetworkReply::isFinished() const
589{
590 return d_func()->isFinished;
591}
592
593/*!
594 \since 4.6
595
596 Returns \c true when the request is still processing and the
597 reply has not finished or was aborted yet.
598
599 \sa isFinished()
600*/
601bool QNetworkReply::isRunning() const
602{
603 return !isFinished();
604}
605
606/*!
607 Returns the URL of the content downloaded or uploaded. Note that
608 the URL may be different from that of the original request. If the
609 QNetworkRequest::FollowRedirectsAttribute was set in the request, then this
610 function returns the current url that the network API is accessing, i.e the
611 url emitted in the QNetworkReply::redirected signal.
612
613 \sa request(), setUrl(), QNetworkRequest::url(), redirected()
614*/
615QUrl QNetworkReply::url() const
616{
617 return d_func()->url;
618}
619
620/*!
621 Returns the value of the known header \a header, if that header
622 was sent by the remote server. If the header was not sent, returns
623 an invalid QVariant.
624
625 \sa rawHeader(), setHeader(), QNetworkRequest::header()
626*/
627QVariant QNetworkReply::header(QNetworkRequest::KnownHeaders header) const
628{
629 return d_func()->cookedHeaders.value(akey: header);
630}
631
632/*!
633 Returns \c true if the raw header of name \a headerName was sent by
634 the remote server
635
636 \sa rawHeader()
637*/
638bool QNetworkReply::hasRawHeader(const QByteArray &headerName) const
639{
640 Q_D(const QNetworkReply);
641 return d->findRawHeader(key: headerName) != d->rawHeaders.constEnd();
642}
643
644/*!
645 Returns the raw contents of the header \a headerName as sent by
646 the remote server. If there is no such header, returns an empty
647 byte array, which may be indistinguishable from an empty
648 header. Use hasRawHeader() to verify if the server sent such
649 header field.
650
651 \sa setRawHeader(), hasRawHeader(), header()
652*/
653QByteArray QNetworkReply::rawHeader(const QByteArray &headerName) const
654{
655 Q_D(const QNetworkReply);
656 QNetworkHeadersPrivate::RawHeadersList::ConstIterator it =
657 d->findRawHeader(key: headerName);
658 if (it != d->rawHeaders.constEnd())
659 return it->second;
660 return QByteArray();
661}
662
663/*! \typedef QNetworkReply::RawHeaderPair
664
665 RawHeaderPair is a QPair<QByteArray, QByteArray> where the first
666 QByteArray is the header name and the second is the header.
667 */
668
669/*!
670 Returns a list of raw header pairs.
671 */
672const QList<QNetworkReply::RawHeaderPair>& QNetworkReply::rawHeaderPairs() const
673{
674 Q_D(const QNetworkReply);
675 return d->rawHeaders;
676}
677
678/*!
679 Returns a list of headers fields that were sent by the remote
680 server, in the order that they were sent. Duplicate headers are
681 merged together and take place of the latter duplicate.
682*/
683QList<QByteArray> QNetworkReply::rawHeaderList() const
684{
685 return d_func()->rawHeadersKeys();
686}
687
688/*!
689 Returns the attribute associated with the code \a code. If the
690 attribute has not been set, it returns an invalid QVariant (type QMetaType::UnknownType).
691
692 You can expect the default values listed in
693 QNetworkRequest::Attribute to be applied to the values returned by
694 this function.
695
696 \sa setAttribute(), QNetworkRequest::Attribute
697*/
698QVariant QNetworkReply::attribute(QNetworkRequest::Attribute code) const
699{
700 return d_func()->attributes.value(akey: code);
701}
702
703#if QT_CONFIG(ssl)
704/*!
705 Returns the SSL configuration and state associated with this
706 reply, if SSL was used. It will contain the remote server's
707 certificate, its certificate chain leading to the Certificate
708 Authority as well as the encryption ciphers in use.
709
710 The peer's certificate and its certificate chain will be known by
711 the time sslErrors() is emitted, if it's emitted.
712*/
713QSslConfiguration QNetworkReply::sslConfiguration() const
714{
715 QSslConfiguration config;
716 sslConfigurationImplementation(config);
717 return config;
718}
719
720/*!
721 Sets the SSL configuration for the network connection associated
722 with this request, if possible, to be that of \a config.
723*/
724void QNetworkReply::setSslConfiguration(const QSslConfiguration &config)
725{
726 setSslConfigurationImplementation(config);
727}
728
729/*!
730 \overload
731 \since 4.6
732
733 If this function is called, the SSL errors given in \a errors
734 will be ignored.
735
736 \note Because most SSL errors are associated with a certificate, for most
737 of them you must set the expected certificate this SSL error is related to.
738 If, for instance, you want to issue a request to a server that uses
739 a self-signed certificate, consider the following snippet:
740
741 \snippet code/src_network_access_qnetworkreply.cpp 0
742
743 Multiple calls to this function will replace the list of errors that
744 were passed in previous calls.
745 You can clear the list of errors you want to ignore by calling this
746 function with an empty list.
747
748 \note If HTTP Strict Transport Security is enabled for QNetworkAccessManager,
749 this function has no effect.
750
751 \sa sslConfiguration(), sslErrors(), QSslSocket::ignoreSslErrors(),
752 QNetworkAccessManager::setStrictTransportSecurityEnabled()
753*/
754void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)
755{
756 ignoreSslErrorsImplementation(errors);
757}
758
759/*!
760 \fn void QNetworkReply::sslConfigurationImplementation(QSslConfiguration &configuration) const
761 \since 5.0
762
763 This virtual method is provided to enable overriding the behavior of
764 sslConfiguration(). sslConfiguration() is a public wrapper for this method.
765 The configuration will be returned in \a configuration.
766
767 \sa sslConfiguration()
768*/
769void QNetworkReply::sslConfigurationImplementation(QSslConfiguration &) const
770{
771}
772
773/*!
774 \fn void QNetworkReply::setSslConfigurationImplementation(const QSslConfiguration &configuration)
775 \since 5.0
776
777 This virtual method is provided to enable overriding the behavior of
778 setSslConfiguration(). setSslConfiguration() is a public wrapper for this method.
779 If you override this method use \a configuration to set the SSL configuration.
780
781 \sa sslConfigurationImplementation(), setSslConfiguration()
782*/
783void QNetworkReply::setSslConfigurationImplementation(const QSslConfiguration &)
784{
785}
786
787/*!
788 \fn void QNetworkReply::ignoreSslErrorsImplementation(const QList<QSslError> &errors)
789 \since 5.0
790
791 This virtual method is provided to enable overriding the behavior of
792 ignoreSslErrors(). ignoreSslErrors() is a public wrapper for this method.
793 \a errors contains the errors the user wishes ignored.
794
795 \sa ignoreSslErrors()
796*/
797void QNetworkReply::ignoreSslErrorsImplementation(const QList<QSslError> &)
798{
799}
800
801#endif // QT_CONFIG(ssl)
802
803/*!
804 If this function is called, SSL errors related to network
805 connection will be ignored, including certificate validation
806 errors.
807
808 \warning Be sure to always let the user inspect the errors
809 reported by the sslErrors() signal, and only call this method
810 upon confirmation from the user that proceeding is ok.
811 If there are unexpected errors, the reply should be aborted.
812 Calling this method without inspecting the actual errors will
813 most likely pose a security risk for your application. Use it
814 with great care!
815
816 This function can be called from the slot connected to the
817 sslErrors() signal, which indicates which errors were
818 found.
819
820 \note If HTTP Strict Transport Security is enabled for QNetworkAccessManager,
821 this function has no effect.
822
823 \sa sslConfiguration(), sslErrors(), QSslSocket::ignoreSslErrors()
824*/
825void QNetworkReply::ignoreSslErrors()
826{
827}
828
829/*!
830 \internal
831*/
832qint64 QNetworkReply::writeData(const char *, qint64)
833{
834 return -1; // you can't write
835}
836
837/*!
838 Sets the associated operation for this object to be \a
839 operation. This value will be returned by operation().
840
841 \note The operation should be set when this object is created and
842 not changed again.
843
844 \sa operation(), setRequest()
845*/
846void QNetworkReply::setOperation(QNetworkAccessManager::Operation operation)
847{
848 Q_D(QNetworkReply);
849 d->operation = operation;
850}
851
852/*!
853 Sets the associated request for this object to be \a request. This
854 value will be returned by request().
855
856 \note The request should be set when this object is created and
857 not changed again.
858
859 \sa request(), setOperation()
860*/
861void QNetworkReply::setRequest(const QNetworkRequest &request)
862{
863 Q_D(QNetworkReply);
864 d->originalRequest = request;
865}
866
867/*!
868 Sets the error condition to be \a errorCode. The human-readable
869 message is set with \a errorString.
870
871 Calling setError() does not emit the errorOccurred(QNetworkReply::NetworkError)
872 signal.
873
874 \sa error(), errorString()
875*/
876void QNetworkReply::setError(NetworkError errorCode, const QString &errorString)
877{
878 Q_D(QNetworkReply);
879 d->errorCode = errorCode;
880 setErrorString(errorString); // in QIODevice
881}
882
883/*!
884 \since 4.8
885 Sets the reply as \a finished.
886
887 After having this set the replies data must not change.
888
889 \sa isFinished()
890*/
891void QNetworkReply::setFinished(bool finished)
892{
893 Q_D(QNetworkReply);
894 d->isFinished = finished;
895}
896
897
898/*!
899 Sets the URL being processed to be \a url. Normally, the URL
900 matches that of the request that was posted, but for a variety of
901 reasons it can be different (for example, a file path being made
902 absolute or canonical).
903
904 \sa url(), request(), QNetworkRequest::url()
905*/
906void QNetworkReply::setUrl(const QUrl &url)
907{
908 Q_D(QNetworkReply);
909 d->url = url;
910}
911
912/*!
913 Sets the known header \a header to be of value \a value. The
914 corresponding raw form of the header will be set as well.
915
916 \sa header(), setRawHeader(), QNetworkRequest::setHeader()
917*/
918void QNetworkReply::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
919{
920 Q_D(QNetworkReply);
921 d->setCookedHeader(header, value);
922}
923
924/*!
925 Sets the raw header \a headerName to be of value \a value. If \a
926 headerName was previously set, it is overridden. Multiple HTTP
927 headers of the same name are functionally equivalent to one single
928 header with the values concatenated, separated by commas.
929
930 If \a headerName matches a known header, the value \a value will
931 be parsed and the corresponding parsed form will also be set.
932
933 \sa rawHeader(), header(), setHeader(), QNetworkRequest::setRawHeader()
934*/
935void QNetworkReply::setRawHeader(const QByteArray &headerName, const QByteArray &value)
936{
937 Q_D(QNetworkReply);
938 d->setRawHeader(key: headerName, value);
939}
940
941/*!
942 Sets the attribute \a code to have value \a value. If \a code was
943 previously set, it will be overridden. If \a value is an invalid
944 QVariant, the attribute will be unset.
945
946 \sa attribute(), QNetworkRequest::setAttribute()
947*/
948void QNetworkReply::setAttribute(QNetworkRequest::Attribute code, const QVariant &value)
949{
950 Q_D(QNetworkReply);
951 if (value.isValid())
952 d->attributes.insert(akey: code, avalue: value);
953 else
954 d->attributes.remove(akey: code);
955}
956
957QT_END_NAMESPACE
958

source code of qtbase/src/network/access/qnetworkreply.cpp