|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtNetwork module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qnetworkreply.h" |
|
43 #include "qnetworkreply_p.h" |
|
44 #include <QtNetwork/qsslconfiguration.h> |
|
45 |
|
46 QT_BEGIN_NAMESPACE |
|
47 |
|
48 QNetworkReplyPrivate::QNetworkReplyPrivate() |
|
49 : readBufferMaxSize(0), |
|
50 operation(QNetworkAccessManager::UnknownOperation), |
|
51 errorCode(QNetworkReply::NoError) |
|
52 { |
|
53 // set the default attribute values |
|
54 attributes.insert(QNetworkRequest::ConnectionEncryptedAttribute, false); |
|
55 } |
|
56 |
|
57 |
|
58 /*! |
|
59 \class QNetworkReply |
|
60 \since 4.4 |
|
61 \brief The QNetworkReply class contains the data and headers for a request |
|
62 sent with QNetworkAccessManager |
|
63 |
|
64 \reentrant |
|
65 \ingroup network |
|
66 \inmodule QtNetwork |
|
67 |
|
68 The QNetworkReply class contains the data and meta data related to |
|
69 a request posted with QNetworkAccessManager. Like QNetworkRequest, |
|
70 it contains a URL and headers (both in parsed and raw form), some |
|
71 information about the reply's state and the contents of the reply |
|
72 itself. |
|
73 |
|
74 QNetworkReply is a sequential-access QIODevice, which means that |
|
75 once data is read from the object, it no longer kept by the |
|
76 device. It is therefore the application's responsibility to keep |
|
77 this data if it needs to. Whenever more data is received from the |
|
78 network and processed, the readyRead() signal is emitted. |
|
79 |
|
80 The downloadProgress() signal is also emitted when data is |
|
81 received, but the number of bytes contained in it may not |
|
82 represent the actual bytes received, if any transformation is done |
|
83 to the contents (for example, decompressing and removing the |
|
84 protocol overhead). |
|
85 |
|
86 Even though QNetworkReply is a QIODevice connected to the contents |
|
87 of the reply, it also emits the uploadProgress() signal, which |
|
88 indicates the progress of the upload for operations that have such |
|
89 content. |
|
90 |
|
91 \note Do not delete the object in the slot connected to the |
|
92 error() or finished() signal. Use deleteLater(). |
|
93 |
|
94 \sa QNetworkRequest, QNetworkAccessManager |
|
95 */ |
|
96 |
|
97 /*! |
|
98 \enum QNetworkReply::NetworkError |
|
99 |
|
100 Indicates all possible error conditions found during the |
|
101 processing of the request. |
|
102 |
|
103 \value NoError no error condition. |
|
104 \note When the HTTP protocol returns a redirect no error will be |
|
105 reported. You can check if there is a redirect with the |
|
106 QNetworkRequest::RedirectionTargetAttribute attribute. |
|
107 |
|
108 \value ConnectionRefusedError the remote server refused the |
|
109 connection (the server is not accepting requests) |
|
110 |
|
111 \value RemoteHostClosedError the remote server closed the |
|
112 connection prematurely, before the entire reply was received and |
|
113 processed |
|
114 |
|
115 \value HostNotFoundError the remote host name was not found |
|
116 (invalid hostname) |
|
117 |
|
118 \value TimeoutError the connection to the remote server |
|
119 timed out |
|
120 |
|
121 \value OperationCanceledError the operation was canceled via calls |
|
122 to abort() or close() before it was finished. |
|
123 |
|
124 \value SslHandshakeFailedError the SSL/TLS handshake failed and the |
|
125 encrypted channel could not be established. The sslErrors() signal |
|
126 should have been emitted. |
|
127 |
|
128 \value ProxyConnectionRefusedError the connection to the proxy |
|
129 server was refused (the proxy server is not accepting requests) |
|
130 |
|
131 \value ProxyConnectionClosedError the proxy server closed the |
|
132 connection prematurely, before the entire reply was received and |
|
133 processed |
|
134 |
|
135 \value ProxyNotFoundError the proxy host name was not |
|
136 found (invalid proxy hostname) |
|
137 |
|
138 \value ProxyTimeoutError the connection to the proxy |
|
139 timed out or the proxy did not reply in time to the request sent |
|
140 |
|
141 \value ProxyAuthenticationRequiredError the proxy requires |
|
142 authentication in order to honour the request but did not accept |
|
143 any credentials offered (if any) |
|
144 |
|
145 \value ContentAccessDenied the access to the remote |
|
146 content was denied (similar to HTTP error 401) |
|
147 |
|
148 \value ContentOperationNotPermittedError the operation requested |
|
149 on the remote content is not permitted |
|
150 |
|
151 \value ContentNotFoundError the remote content was not |
|
152 found at the server (similar to HTTP error 404) |
|
153 |
|
154 \value AuthenticationRequiredError the remote server requires |
|
155 authentication to serve the content but the credentials provided |
|
156 were not accepted (if any) |
|
157 |
|
158 \value ContentReSendError the request needed to be sent |
|
159 again, but this failed for example because the upload data |
|
160 could not be read a second time. |
|
161 |
|
162 \value ProtocolUnknownError the Network Access API cannot |
|
163 honor the request because the protocol is not known |
|
164 |
|
165 \value ProtocolInvalidOperationError the requested operation is |
|
166 invalid for this protocol |
|
167 |
|
168 \value UnknownNetworkError an unknown network-related |
|
169 error was detected |
|
170 |
|
171 \value UnknownProxyError an unknown proxy-related error |
|
172 was detected |
|
173 |
|
174 \value UnknownContentError an unknonwn error related to |
|
175 the remote content was detected |
|
176 |
|
177 \value ProtocolFailure a breakdown in protocol was |
|
178 detected (parsing error, invalid or unexpected responses, etc.) |
|
179 |
|
180 \sa error() |
|
181 */ |
|
182 |
|
183 /*! |
|
184 \fn void QNetworkReply::sslErrors(const QList<QSslError> &errors) |
|
185 |
|
186 This signal is emitted if the SSL/TLS session encountered errors |
|
187 during the set up, including certificate verification errors. The |
|
188 \a errors parameter contains the list of errors. |
|
189 |
|
190 To indicate that the errors are not fatal and that the connection |
|
191 should proceed, the ignoreSslErrors() function should be called |
|
192 from the slot connected to this signal. If it is not called, the |
|
193 SSL session will be torn down before any data is exchanged |
|
194 (including the URL). |
|
195 |
|
196 This signal can be used to display an error message to the user |
|
197 indicating that security may be compromised and display the |
|
198 SSL settings (see sslConfiguration() to obtain it). If the user |
|
199 decides to proceed after analyzing the remote certificate, the |
|
200 slot should call ignoreSslErrors(). |
|
201 |
|
202 \sa QSslSocket::sslErrors(), QNetworkAccessManager::sslErrors(), |
|
203 sslConfiguration(), ignoreSslErrors() |
|
204 */ |
|
205 |
|
206 /*! |
|
207 \fn void QNetworkReply::metaDataChanged() |
|
208 |
|
209 \omit FIXME: Update name? \endomit |
|
210 |
|
211 This signal is emitted whenever the metadata in this reply |
|
212 changes. metadata is any information that is not the content |
|
213 (data) itself, including the network headers. In the majority of |
|
214 cases, the metadata will be known fully by the time the first |
|
215 byte of data is received. However, it is possible to receive |
|
216 updates of headers or other metadata during the processing of the |
|
217 data. |
|
218 |
|
219 \sa header(), rawHeaderList(), rawHeader(), hasRawHeader() |
|
220 */ |
|
221 |
|
222 /*! |
|
223 \fn void QNetworkReply::finished() |
|
224 |
|
225 This signal is emitted when the reply has finished |
|
226 processing. After this signal is emitted, there will be no more |
|
227 updates to the reply's data or metadata. |
|
228 |
|
229 Unless close() has been called, the reply will be still be opened |
|
230 for reading, so the data can be retrieved by calls to read() or |
|
231 readAll(). In particular, if no calls to read() were made as a |
|
232 result of readyRead(), a call to readAll() will retrieve the full |
|
233 contents in a QByteArray. |
|
234 |
|
235 This signal is emitted in tandem with |
|
236 QNetworkAccessManager::finished() where that signal's reply |
|
237 parameter is this object. |
|
238 |
|
239 \note Do not delete the object in the slot connected to this |
|
240 signal. Use deleteLater(). |
|
241 |
|
242 \sa QNetworkAccessManager::finished() |
|
243 */ |
|
244 |
|
245 /*! |
|
246 \fn void QNetworkReply::error(QNetworkReply::NetworkError code) |
|
247 |
|
248 This signal is emitted when the reply detects an error in |
|
249 processing. The finished() signal will probably follow, indicating |
|
250 that the connection is over. |
|
251 |
|
252 The \a code parameter contains the code of the error that was |
|
253 detected. Call errorString() to obtain a textual representation of |
|
254 the error condition. |
|
255 |
|
256 \note Do not delete the object in the slot connected to this |
|
257 signal. Use deleteLater(). |
|
258 |
|
259 \sa error(), errorString() |
|
260 */ |
|
261 |
|
262 /*! |
|
263 \fn void QNetworkReply::uploadProgress(qint64 bytesSent, qint64 bytesTotal) |
|
264 |
|
265 This signal is emitted to indicate the progress of the upload part |
|
266 of this network request, if there's any. If there's no upload |
|
267 associated with this request, this signal will not be emitted. |
|
268 |
|
269 The \a bytesSent |
|
270 parameter indicates the number of bytes uploaded, while \a |
|
271 bytesTotal indicates the total number of bytes to be uploaded. If |
|
272 the number of bytes to be uploaded could not be determined, \a |
|
273 bytesTotal will be -1. |
|
274 |
|
275 The upload is finished when \a bytesSent is equal to \a |
|
276 bytesTotal. At that time, \a bytesTotal will not be -1. |
|
277 |
|
278 This signal is suitable to connecting to QProgressBar::setValue() |
|
279 to update the QProgressBar that provides user feedback. |
|
280 |
|
281 \sa downloadProgress() |
|
282 */ |
|
283 |
|
284 /*! |
|
285 \fn void QNetworkReply::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) |
|
286 |
|
287 This signal is emitted to indicate the progress of the download |
|
288 part of this network request, if there's any. If there's no |
|
289 download associated with this request, this signal will be emitted |
|
290 once with 0 as the value of both \a bytesReceived and \a |
|
291 bytesTotal. |
|
292 |
|
293 The \a bytesReceived parameter indicates the number of bytes |
|
294 received, while \a bytesTotal indicates the total number of bytes |
|
295 expected to be downloaded. If the number of bytes to be downloaded |
|
296 is not known, \a bytesTotal will be -1. |
|
297 |
|
298 The download is finished when \a bytesReceived is equal to \a |
|
299 bytesTotal. At that time, \a bytesTotal will not be -1. |
|
300 |
|
301 This signal is suitable to connecting to QProgressBar::setValue() |
|
302 to update the QProgressBar that provides user feedback. |
|
303 |
|
304 Note that the values of both \a bytesReceived and \a bytesTotal |
|
305 may be different from size(), the total number of bytes |
|
306 obtained through read() or readAll(), or the value of the |
|
307 header(ContentLengthHeader). The reason for that is that there may |
|
308 be protocol overhead or the data may be compressed during the |
|
309 download. |
|
310 |
|
311 \sa uploadProgress(), bytesAvailable() |
|
312 */ |
|
313 |
|
314 /*! |
|
315 \fn void QNetworkReply::abort() |
|
316 |
|
317 Aborts the operation immediately and close down any network |
|
318 connections still open. Uploads still in progress are also |
|
319 aborted. |
|
320 |
|
321 \sa close() |
|
322 */ |
|
323 |
|
324 /*! |
|
325 Creates a QNetworkReply object with parent \a parent. |
|
326 |
|
327 You cannot directly instantiate QNetworkReply objects. Use |
|
328 QNetworkAccessManager functions to do that. |
|
329 */ |
|
330 QNetworkReply::QNetworkReply(QObject *parent) |
|
331 : QIODevice(*new QNetworkReplyPrivate, parent) |
|
332 { |
|
333 } |
|
334 |
|
335 /*! |
|
336 \internal |
|
337 */ |
|
338 QNetworkReply::QNetworkReply(QNetworkReplyPrivate &dd, QObject *parent) |
|
339 : QIODevice(dd, parent) |
|
340 { |
|
341 } |
|
342 |
|
343 /*! |
|
344 Disposes of this reply and frees any resources associated with |
|
345 it. If any network connections are still open, they will be |
|
346 closed. |
|
347 |
|
348 \sa abort(), close() |
|
349 */ |
|
350 QNetworkReply::~QNetworkReply() |
|
351 { |
|
352 } |
|
353 |
|
354 /*! |
|
355 Closes this device for reading. Unread data is discarded, but the |
|
356 network resources are not discarded until they are finished. In |
|
357 particular, if any upload is in progress, it will continue until |
|
358 it is done. |
|
359 |
|
360 The finished() signal is emitted when all operations are over and |
|
361 the network resources are freed. |
|
362 |
|
363 \sa abort(), finished() |
|
364 */ |
|
365 void QNetworkReply::close() |
|
366 { |
|
367 QIODevice::close(); |
|
368 } |
|
369 |
|
370 /*! |
|
371 \internal |
|
372 */ |
|
373 bool QNetworkReply::isSequential() const |
|
374 { |
|
375 return true; |
|
376 } |
|
377 |
|
378 /*! |
|
379 Returns the size of the read buffer, in bytes. |
|
380 |
|
381 \sa setReadBufferSize() |
|
382 */ |
|
383 qint64 QNetworkReply::readBufferSize() const |
|
384 { |
|
385 return d_func()->readBufferMaxSize; |
|
386 } |
|
387 |
|
388 /*! |
|
389 Sets the size of the read buffer to be \a size bytes. The read |
|
390 buffer is the buffer that holds data that is being downloaded off |
|
391 the network, before it is read with QIODevice::read(). Setting the |
|
392 buffer size to 0 will make the buffer unlimited in size. |
|
393 |
|
394 QNetworkReply will try to stop reading from the network once this |
|
395 buffer is full (i.e., bytesAvailable() returns \a size or more), |
|
396 thus causing the download to throttle down as well. If the buffer |
|
397 is not limited in size, QNetworkReply will try to download as fast |
|
398 as possible from the network. |
|
399 |
|
400 Unlike QAbstractSocket::setReadBufferSize(), QNetworkReply cannot |
|
401 guarantee precision in the read buffer size. That is, |
|
402 bytesAvailable() can return more than \a size. |
|
403 |
|
404 \sa readBufferSize() |
|
405 */ |
|
406 void QNetworkReply::setReadBufferSize(qint64 size) |
|
407 { |
|
408 Q_D(QNetworkReply); |
|
409 d->readBufferMaxSize = size; |
|
410 } |
|
411 |
|
412 /*! |
|
413 Returns the QNetworkAccessManager that was used to create this |
|
414 QNetworkReply object. Initially, it is also the parent object. |
|
415 */ |
|
416 QNetworkAccessManager *QNetworkReply::manager() const |
|
417 { |
|
418 return d_func()->manager; |
|
419 } |
|
420 |
|
421 /*! |
|
422 Returns the request that was posted for this reply. In special, |
|
423 note that the URL for the request may be different than that of |
|
424 the reply. |
|
425 |
|
426 \sa QNetworkRequest::url(), url(), setRequest() |
|
427 */ |
|
428 QNetworkRequest QNetworkReply::request() const |
|
429 { |
|
430 return d_func()->request; |
|
431 } |
|
432 |
|
433 /*! |
|
434 Returns the operation that was posted for this reply. |
|
435 |
|
436 \sa setOperation() |
|
437 */ |
|
438 QNetworkAccessManager::Operation QNetworkReply::operation() const |
|
439 { |
|
440 return d_func()->operation; |
|
441 } |
|
442 |
|
443 /*! |
|
444 Returns the error that was found during the processing of this |
|
445 request. If no error was found, returns NoError. |
|
446 |
|
447 \sa setError() |
|
448 */ |
|
449 QNetworkReply::NetworkError QNetworkReply::error() const |
|
450 { |
|
451 return d_func()->errorCode; |
|
452 } |
|
453 |
|
454 /*! |
|
455 \since 4.6 |
|
456 |
|
457 Returns true when the reply has finished or was aborted. |
|
458 |
|
459 \sa isRunning() |
|
460 */ |
|
461 bool QNetworkReply::isFinished() const |
|
462 { |
|
463 return d_func()->isFinished(); |
|
464 } |
|
465 |
|
466 /*! |
|
467 \since 4.6 |
|
468 |
|
469 Returns true when the request is still processing and the |
|
470 reply has not finished or was aborted yet. |
|
471 |
|
472 \sa isFinished() |
|
473 */ |
|
474 bool QNetworkReply::isRunning() const |
|
475 { |
|
476 return !isFinished(); |
|
477 } |
|
478 |
|
479 /*! |
|
480 Returns the URL of the content downloaded or uploaded. Note that |
|
481 the URL may be different from that of the original request. |
|
482 |
|
483 \sa request(), setUrl(), QNetworkRequest::url() |
|
484 */ |
|
485 QUrl QNetworkReply::url() const |
|
486 { |
|
487 return d_func()->url; |
|
488 } |
|
489 |
|
490 /*! |
|
491 Returns the value of the known header \a header, if that header |
|
492 was sent by the remote server. If the header was not sent, returns |
|
493 an invalid QVariant. |
|
494 |
|
495 \sa rawHeader(), setHeader(), QNetworkRequest::header() |
|
496 */ |
|
497 QVariant QNetworkReply::header(QNetworkRequest::KnownHeaders header) const |
|
498 { |
|
499 return d_func()->cookedHeaders.value(header); |
|
500 } |
|
501 |
|
502 /*! |
|
503 Returns true if the raw header of name \a headerName was sent by |
|
504 the remote server |
|
505 |
|
506 \sa rawHeader() |
|
507 */ |
|
508 bool QNetworkReply::hasRawHeader(const QByteArray &headerName) const |
|
509 { |
|
510 Q_D(const QNetworkReply); |
|
511 return d->findRawHeader(headerName) != d->rawHeaders.constEnd(); |
|
512 } |
|
513 |
|
514 /*! |
|
515 Returns the raw contents of the header \a headerName as sent by |
|
516 the remote server. If there is no such header, returns an empty |
|
517 byte array, which may be indistinguishable from an empty |
|
518 header. Use hasRawHeader() to verify if the server sent such |
|
519 header field. |
|
520 |
|
521 \sa setRawHeader(), hasRawHeader(), header() |
|
522 */ |
|
523 QByteArray QNetworkReply::rawHeader(const QByteArray &headerName) const |
|
524 { |
|
525 Q_D(const QNetworkReply); |
|
526 QNetworkHeadersPrivate::RawHeadersList::ConstIterator it = |
|
527 d->findRawHeader(headerName); |
|
528 if (it != d->rawHeaders.constEnd()) |
|
529 return it->second; |
|
530 return QByteArray(); |
|
531 } |
|
532 |
|
533 /*! |
|
534 Returns a list of headers fields that were sent by the remote |
|
535 server, in the order that they were sent. Duplicate headers are |
|
536 merged together and take place of the latter duplicate. |
|
537 */ |
|
538 QList<QByteArray> QNetworkReply::rawHeaderList() const |
|
539 { |
|
540 return d_func()->rawHeadersKeys(); |
|
541 } |
|
542 |
|
543 /*! |
|
544 Returns the attribute associated with the code \a code. If the |
|
545 attribute has not been set, it returns an invalid QVariant (type QVariant::Null). |
|
546 |
|
547 You can expect the default values listed in |
|
548 QNetworkRequest::Attribute to be applied to the values returned by |
|
549 this function. |
|
550 |
|
551 \sa setAttribute(), QNetworkRequest::Attribute |
|
552 */ |
|
553 QVariant QNetworkReply::attribute(QNetworkRequest::Attribute code) const |
|
554 { |
|
555 return d_func()->attributes.value(code); |
|
556 } |
|
557 |
|
558 #ifndef QT_NO_OPENSSL |
|
559 /*! |
|
560 Returns the SSL configuration and state associated with this |
|
561 reply, if SSL was used. It will contain the remote server's |
|
562 certificate, its certificate chain leading to the Certificate |
|
563 Authority as well as the encryption ciphers in use. |
|
564 |
|
565 The peer's certificate and its certificate chain will be known by |
|
566 the time sslErrors() is emitted, if it's emitted. |
|
567 */ |
|
568 QSslConfiguration QNetworkReply::sslConfiguration() const |
|
569 { |
|
570 QSslConfiguration config; |
|
571 |
|
572 // determine if we support this extension |
|
573 int id = metaObject()->indexOfMethod("sslConfigurationImplementation()"); |
|
574 if (id != -1) { |
|
575 void *arr[] = { &config, 0 }; |
|
576 const_cast<QNetworkReply *>(this)->qt_metacall(QMetaObject::InvokeMetaMethod, id, arr); |
|
577 } |
|
578 return config; |
|
579 } |
|
580 |
|
581 /*! |
|
582 Sets the SSL configuration for the network connection associated |
|
583 with this request, if possible, to be that of \a config. |
|
584 */ |
|
585 void QNetworkReply::setSslConfiguration(const QSslConfiguration &config) |
|
586 { |
|
587 if (config.isNull()) |
|
588 return; |
|
589 |
|
590 int id = metaObject()->indexOfMethod("setSslConfigurationImplementation(QSslConfiguration)"); |
|
591 if (id != -1) { |
|
592 QSslConfiguration copy(config); |
|
593 void *arr[] = { 0, © }; |
|
594 qt_metacall(QMetaObject::InvokeMetaMethod, id, arr); |
|
595 } |
|
596 } |
|
597 |
|
598 /*! |
|
599 \overload |
|
600 \since 4.6 |
|
601 |
|
602 If this function is called, the SSL errors given in \a errors |
|
603 will be ignored. |
|
604 |
|
605 Note that you can set the expected certificate in the SSL error: |
|
606 If, for instance, you want to issue a request to a server that uses |
|
607 a self-signed certificate, consider the following snippet: |
|
608 |
|
609 \snippet doc/src/snippets/code/src_network_access_qnetworkreply.cpp 0 |
|
610 |
|
611 Multiple calls to this function will replace the list of errors that |
|
612 were passed in previous calls. |
|
613 You can clear the list of errors you want to ignore by calling this |
|
614 function with an empty list. |
|
615 |
|
616 \sa sslConfiguration(), sslErrors(), QSslSocket::ignoreSslErrors() |
|
617 */ |
|
618 void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors) |
|
619 { |
|
620 // do this cryptic trick, because we could not add a virtual method to this class later on |
|
621 // since that breaks binary compatibility |
|
622 int id = metaObject()->indexOfMethod("ignoreSslErrorsImplementation(QList<QSslError>)"); |
|
623 if (id != -1) { |
|
624 QList<QSslError> copy(errors); |
|
625 void *arr[] = { 0, © }; |
|
626 qt_metacall(QMetaObject::InvokeMetaMethod, id, arr); |
|
627 } |
|
628 } |
|
629 #endif |
|
630 |
|
631 /*! |
|
632 If this function is called, SSL errors related to network |
|
633 connection will be ignored, including certificate validation |
|
634 errors. |
|
635 |
|
636 Note that calling this function without restraint may pose a |
|
637 security risk for your application. Use it with care. |
|
638 |
|
639 This function can be called from the slot connected to the |
|
640 sslErrors() signal, which indicates which errors were |
|
641 found. |
|
642 |
|
643 \sa sslConfiguration(), sslErrors(), QSslSocket::ignoreSslErrors() |
|
644 */ |
|
645 void QNetworkReply::ignoreSslErrors() |
|
646 { |
|
647 } |
|
648 |
|
649 /*! |
|
650 \internal |
|
651 */ |
|
652 qint64 QNetworkReply::writeData(const char *, qint64) |
|
653 { |
|
654 return -1; // you can't write |
|
655 } |
|
656 |
|
657 /*! |
|
658 Sets the associated operation for this object to be \a |
|
659 operation. This value will be returned by operation(). |
|
660 |
|
661 Note: the operation should be set when this object is created and |
|
662 not changed again. |
|
663 |
|
664 \sa operation(), setRequest() |
|
665 */ |
|
666 void QNetworkReply::setOperation(QNetworkAccessManager::Operation operation) |
|
667 { |
|
668 Q_D(QNetworkReply); |
|
669 d->operation = operation; |
|
670 } |
|
671 |
|
672 /*! |
|
673 Sets the associated request for this object to be \a request. This |
|
674 value will be returned by request(). |
|
675 |
|
676 Note: the request should be set when this object is created and |
|
677 not changed again. |
|
678 |
|
679 \sa request(), setOperation() |
|
680 */ |
|
681 void QNetworkReply::setRequest(const QNetworkRequest &request) |
|
682 { |
|
683 Q_D(QNetworkReply); |
|
684 d->request = request; |
|
685 } |
|
686 |
|
687 /*! |
|
688 Sets the error condition to be \a errorCode. The human-readable |
|
689 message is set with \a errorString. |
|
690 |
|
691 Calling setError() does not emit the error(QNetworkReply::NetworkError) |
|
692 signal. |
|
693 |
|
694 \sa error(), errorString() |
|
695 */ |
|
696 void QNetworkReply::setError(NetworkError errorCode, const QString &errorString) |
|
697 { |
|
698 Q_D(QNetworkReply); |
|
699 d->errorCode = errorCode; |
|
700 setErrorString(errorString); // in QIODevice |
|
701 } |
|
702 |
|
703 /*! |
|
704 Sets the URL being processed to be \a url. Normally, the URL |
|
705 matches that of the request that was posted, but for a variety of |
|
706 reasons it can be different (for example, a file path being made |
|
707 absolute or canonical). |
|
708 |
|
709 \sa url(), request(), QNetworkRequest::url() |
|
710 */ |
|
711 void QNetworkReply::setUrl(const QUrl &url) |
|
712 { |
|
713 Q_D(QNetworkReply); |
|
714 d->url = url; |
|
715 } |
|
716 |
|
717 /*! |
|
718 Sets the known header \a header to be of value \a value. The |
|
719 corresponding raw form of the header will be set as well. |
|
720 |
|
721 \sa header(), setRawHeader(), QNetworkRequest::setHeader() |
|
722 */ |
|
723 void QNetworkReply::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value) |
|
724 { |
|
725 Q_D(QNetworkReply); |
|
726 d->setCookedHeader(header, value); |
|
727 } |
|
728 |
|
729 /*! |
|
730 Sets the raw header \a headerName to be of value \a value. If \a |
|
731 headerName was previously set, it is overridden. Multiple HTTP |
|
732 headers of the same name are functionally equivalent to one single |
|
733 header with the values concatenated, separated by commas. |
|
734 |
|
735 If \a headerName matches a known header, the value \a value will |
|
736 be parsed and the corresponding parsed form will also be set. |
|
737 |
|
738 \sa rawHeader(), header(), setHeader(), QNetworkRequest::setRawHeader() |
|
739 */ |
|
740 void QNetworkReply::setRawHeader(const QByteArray &headerName, const QByteArray &value) |
|
741 { |
|
742 Q_D(QNetworkReply); |
|
743 d->setRawHeader(headerName, value); |
|
744 } |
|
745 |
|
746 /*! |
|
747 Sets the attribute \a code to have value \a value. If \a code was |
|
748 previously set, it will be overridden. If \a value is an invalid |
|
749 QVariant, the attribute will be unset. |
|
750 |
|
751 \sa attribute(), QNetworkRequest::setAttribute() |
|
752 */ |
|
753 void QNetworkReply::setAttribute(QNetworkRequest::Attribute code, const QVariant &value) |
|
754 { |
|
755 Q_D(QNetworkReply); |
|
756 if (value.isValid()) |
|
757 d->attributes.insert(code, value); |
|
758 else |
|
759 d->attributes.remove(code); |
|
760 } |
|
761 |
|
762 QT_END_NAMESPACE |