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

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