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