util/src/network/access/qnetworkreply.cpp
changeset 7 f7bc934e204c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 unknown 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     You can also use isFinished() to check if a QNetworkReply
       
   243     has finished even before you receive the finished() signal.
       
   244 
       
   245     \sa QNetworkAccessManager::finished(), isFinished()
       
   246 */
       
   247 
       
   248 /*!
       
   249     \fn void QNetworkReply::error(QNetworkReply::NetworkError code)
       
   250 
       
   251     This signal is emitted when the reply detects an error in
       
   252     processing. The finished() signal will probably follow, indicating
       
   253     that the connection is over.
       
   254 
       
   255     The \a code parameter contains the code of the error that was
       
   256     detected. Call errorString() to obtain a textual representation of
       
   257     the error condition.
       
   258 
       
   259     \note Do not delete the object in the slot connected to this
       
   260     signal. Use deleteLater().
       
   261 
       
   262     \sa error(), errorString()
       
   263 */
       
   264 
       
   265 /*!
       
   266     \fn void QNetworkReply::uploadProgress(qint64 bytesSent, qint64 bytesTotal)
       
   267 
       
   268     This signal is emitted to indicate the progress of the upload part
       
   269     of this network request, if there's any. If there's no upload
       
   270     associated with this request, this signal will not be emitted.
       
   271 
       
   272     The \a bytesSent
       
   273     parameter indicates the number of bytes uploaded, while \a
       
   274     bytesTotal indicates the total number of bytes to be uploaded. If
       
   275     the number of bytes to be uploaded could not be determined, \a
       
   276     bytesTotal will be -1.
       
   277 
       
   278     The upload is finished when \a bytesSent is equal to \a
       
   279     bytesTotal. At that time, \a bytesTotal will not be -1.
       
   280 
       
   281     This signal is suitable to connecting to QProgressBar::setValue()
       
   282     to update the QProgressBar that provides user feedback.
       
   283 
       
   284     \sa downloadProgress()
       
   285 */
       
   286 
       
   287 /*!
       
   288     \fn void QNetworkReply::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
       
   289 
       
   290     This signal is emitted to indicate the progress of the download
       
   291     part of this network request, if there's any. If there's no
       
   292     download associated with this request, this signal will be emitted
       
   293     once with 0 as the value of both \a bytesReceived and \a
       
   294     bytesTotal.
       
   295 
       
   296     The \a bytesReceived parameter indicates the number of bytes
       
   297     received, while \a bytesTotal indicates the total number of bytes
       
   298     expected to be downloaded. If the number of bytes to be downloaded
       
   299     is not known, \a bytesTotal will be -1.
       
   300 
       
   301     The download is finished when \a bytesReceived is equal to \a
       
   302     bytesTotal. At that time, \a bytesTotal will not be -1.
       
   303 
       
   304     This signal is suitable to connecting to QProgressBar::setValue()
       
   305     to update the QProgressBar that provides user feedback.
       
   306 
       
   307     Note that the values of both \a bytesReceived and \a bytesTotal
       
   308     may be different from size(), the total number of bytes
       
   309     obtained through read() or readAll(), or the value of the
       
   310     header(ContentLengthHeader). The reason for that is that there may
       
   311     be protocol overhead or the data may be compressed during the
       
   312     download.
       
   313 
       
   314     \sa uploadProgress(), bytesAvailable()
       
   315 */
       
   316 
       
   317 /*!
       
   318     \fn void QNetworkReply::abort()
       
   319 
       
   320     Aborts the operation immediately and close down any network
       
   321     connections still open. Uploads still in progress are also
       
   322     aborted.
       
   323 
       
   324     \sa close()
       
   325 */
       
   326 
       
   327 /*!
       
   328     Creates a QNetworkReply object with parent \a parent.
       
   329 
       
   330     You cannot directly instantiate QNetworkReply objects. Use
       
   331     QNetworkAccessManager functions to do that.
       
   332 */
       
   333 QNetworkReply::QNetworkReply(QObject *parent)
       
   334     : QIODevice(*new QNetworkReplyPrivate, parent)
       
   335 {
       
   336 }
       
   337 
       
   338 /*!
       
   339     \internal
       
   340 */
       
   341 QNetworkReply::QNetworkReply(QNetworkReplyPrivate &dd, QObject *parent)
       
   342     : QIODevice(dd, parent)
       
   343 {
       
   344 }
       
   345 
       
   346 /*!
       
   347     Disposes of this reply and frees any resources associated with
       
   348     it. If any network connections are still open, they will be
       
   349     closed.
       
   350 
       
   351     \sa abort(), close()
       
   352 */
       
   353 QNetworkReply::~QNetworkReply()
       
   354 {
       
   355 }
       
   356 
       
   357 /*!
       
   358     Closes this device for reading. Unread data is discarded, but the
       
   359     network resources are not discarded until they are finished. In
       
   360     particular, if any upload is in progress, it will continue until
       
   361     it is done.
       
   362 
       
   363     The finished() signal is emitted when all operations are over and
       
   364     the network resources are freed.
       
   365 
       
   366     \sa abort(), finished()
       
   367 */
       
   368 void QNetworkReply::close()
       
   369 {
       
   370     QIODevice::close();
       
   371 }
       
   372 
       
   373 /*!
       
   374     \internal
       
   375 */
       
   376 bool QNetworkReply::isSequential() const
       
   377 {
       
   378     return true;
       
   379 }
       
   380 
       
   381 /*!
       
   382     Returns the size of the read buffer, in bytes.
       
   383 
       
   384     \sa setReadBufferSize()
       
   385 */
       
   386 qint64 QNetworkReply::readBufferSize() const
       
   387 {
       
   388     return d_func()->readBufferMaxSize;
       
   389 }
       
   390 
       
   391 /*!
       
   392     Sets the size of the read buffer to be \a size bytes. The read
       
   393     buffer is the buffer that holds data that is being downloaded off
       
   394     the network, before it is read with QIODevice::read(). Setting the
       
   395     buffer size to 0 will make the buffer unlimited in size.
       
   396 
       
   397     QNetworkReply will try to stop reading from the network once this
       
   398     buffer is full (i.e., bytesAvailable() returns \a size or more),
       
   399     thus causing the download to throttle down as well. If the buffer
       
   400     is not limited in size, QNetworkReply will try to download as fast
       
   401     as possible from the network.
       
   402 
       
   403     Unlike QAbstractSocket::setReadBufferSize(), QNetworkReply cannot
       
   404     guarantee precision in the read buffer size. That is,
       
   405     bytesAvailable() can return more than \a size.
       
   406 
       
   407     \sa readBufferSize()
       
   408 */
       
   409 void QNetworkReply::setReadBufferSize(qint64 size)
       
   410 {
       
   411     Q_D(QNetworkReply);
       
   412     d->readBufferMaxSize = size;
       
   413 }
       
   414 
       
   415 /*!
       
   416     Returns the QNetworkAccessManager that was used to create this
       
   417     QNetworkReply object. Initially, it is also the parent object.
       
   418 */
       
   419 QNetworkAccessManager *QNetworkReply::manager() const
       
   420 {
       
   421     return d_func()->manager;
       
   422 }
       
   423 
       
   424 /*!
       
   425     Returns the request that was posted for this reply. In special,
       
   426     note that the URL for the request may be different than that of
       
   427     the reply.
       
   428 
       
   429     \sa QNetworkRequest::url(), url(), setRequest()
       
   430 */
       
   431 QNetworkRequest QNetworkReply::request() const
       
   432 {
       
   433     return d_func()->request;
       
   434 }
       
   435 
       
   436 /*!
       
   437     Returns the operation that was posted for this reply.
       
   438 
       
   439     \sa setOperation()
       
   440 */
       
   441 QNetworkAccessManager::Operation QNetworkReply::operation() const
       
   442 {
       
   443     return d_func()->operation;
       
   444 }
       
   445 
       
   446 /*!
       
   447     Returns the error that was found during the processing of this
       
   448     request. If no error was found, returns NoError.
       
   449 
       
   450     \sa setError()
       
   451 */
       
   452 QNetworkReply::NetworkError QNetworkReply::error() const
       
   453 {
       
   454     return d_func()->errorCode;
       
   455 }
       
   456 
       
   457 /*!
       
   458     \since 4.6
       
   459 
       
   460     Returns true when the reply has finished or was aborted.
       
   461 
       
   462     \sa isRunning()
       
   463 */
       
   464 bool QNetworkReply::isFinished() const
       
   465 {
       
   466     return d_func()->isFinished();
       
   467 }
       
   468 
       
   469 /*!
       
   470     \since 4.6
       
   471 
       
   472     Returns true when the request is still processing and the
       
   473     reply has not finished or was aborted yet.
       
   474 
       
   475     \sa isFinished()
       
   476 */
       
   477 bool QNetworkReply::isRunning() const
       
   478 {
       
   479     return !isFinished();
       
   480 }
       
   481 
       
   482 /*!
       
   483     Returns the URL of the content downloaded or uploaded. Note that
       
   484     the URL may be different from that of the original request.
       
   485 
       
   486     \sa request(), setUrl(), QNetworkRequest::url()
       
   487 */
       
   488 QUrl QNetworkReply::url() const
       
   489 {
       
   490     return d_func()->url;
       
   491 }
       
   492 
       
   493 /*!
       
   494     Returns the value of the known header \a header, if that header
       
   495     was sent by the remote server. If the header was not sent, returns
       
   496     an invalid QVariant.
       
   497 
       
   498     \sa rawHeader(), setHeader(), QNetworkRequest::header()
       
   499 */
       
   500 QVariant QNetworkReply::header(QNetworkRequest::KnownHeaders header) const
       
   501 {
       
   502     return d_func()->cookedHeaders.value(header);
       
   503 }
       
   504 
       
   505 /*!
       
   506     Returns true if the raw header of name \a headerName was sent by
       
   507     the remote server
       
   508 
       
   509     \sa rawHeader()
       
   510 */
       
   511 bool QNetworkReply::hasRawHeader(const QByteArray &headerName) const
       
   512 {
       
   513     Q_D(const QNetworkReply);
       
   514     return d->findRawHeader(headerName) != d->rawHeaders.constEnd();
       
   515 }
       
   516 
       
   517 /*!
       
   518     Returns the raw contents of the header \a headerName as sent by
       
   519     the remote server. If there is no such header, returns an empty
       
   520     byte array, which may be indistinguishable from an empty
       
   521     header. Use hasRawHeader() to verify if the server sent such
       
   522     header field.
       
   523 
       
   524     \sa setRawHeader(), hasRawHeader(), header()
       
   525 */
       
   526 QByteArray QNetworkReply::rawHeader(const QByteArray &headerName) const
       
   527 {
       
   528     Q_D(const QNetworkReply);
       
   529     QNetworkHeadersPrivate::RawHeadersList::ConstIterator it =
       
   530         d->findRawHeader(headerName);
       
   531     if (it != d->rawHeaders.constEnd())
       
   532         return it->second;
       
   533     return QByteArray();
       
   534 }
       
   535 
       
   536 /*!
       
   537     Returns a list of headers fields that were sent by the remote
       
   538     server, in the order that they were sent. Duplicate headers are
       
   539     merged together and take place of the latter duplicate.
       
   540 */
       
   541 QList<QByteArray> QNetworkReply::rawHeaderList() const
       
   542 {
       
   543     return d_func()->rawHeadersKeys();
       
   544 }
       
   545 
       
   546 /*!
       
   547     Returns the attribute associated with the code \a code. If the
       
   548     attribute has not been set, it returns an invalid QVariant (type QVariant::Null).
       
   549 
       
   550     You can expect the default values listed in
       
   551     QNetworkRequest::Attribute to be applied to the values returned by
       
   552     this function.
       
   553 
       
   554     \sa setAttribute(), QNetworkRequest::Attribute
       
   555 */
       
   556 QVariant QNetworkReply::attribute(QNetworkRequest::Attribute code) const
       
   557 {
       
   558     return d_func()->attributes.value(code);
       
   559 }
       
   560 
       
   561 #ifndef QT_NO_OPENSSL
       
   562 /*!
       
   563     Returns the SSL configuration and state associated with this
       
   564     reply, if SSL was used. It will contain the remote server's
       
   565     certificate, its certificate chain leading to the Certificate
       
   566     Authority as well as the encryption ciphers in use.
       
   567 
       
   568     The peer's certificate and its certificate chain will be known by
       
   569     the time sslErrors() is emitted, if it's emitted.
       
   570 */
       
   571 QSslConfiguration QNetworkReply::sslConfiguration() const
       
   572 {
       
   573     QSslConfiguration config;
       
   574 
       
   575     // determine if we support this extension
       
   576     int id = metaObject()->indexOfMethod("sslConfigurationImplementation()");
       
   577     if (id != -1) {
       
   578         void *arr[] = { &config, 0 };
       
   579         const_cast<QNetworkReply *>(this)->qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
       
   580     }
       
   581     return config;
       
   582 }
       
   583 
       
   584 /*!
       
   585     Sets the SSL configuration for the network connection associated
       
   586     with this request, if possible, to be that of \a config.
       
   587 */
       
   588 void QNetworkReply::setSslConfiguration(const QSslConfiguration &config)
       
   589 {
       
   590     if (config.isNull())
       
   591         return;
       
   592 
       
   593     int id = metaObject()->indexOfMethod("setSslConfigurationImplementation(QSslConfiguration)");
       
   594     if (id != -1) {
       
   595         QSslConfiguration copy(config);
       
   596         void *arr[] = { 0, &copy };
       
   597         qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
       
   598     }
       
   599 }
       
   600 
       
   601 /*!
       
   602     \overload
       
   603     \since 4.6
       
   604 
       
   605     If this function is called, the SSL errors given in \a errors
       
   606     will be ignored.
       
   607 
       
   608     Note that you can set the expected certificate in the SSL error:
       
   609     If, for instance, you want to issue a request to a server that uses
       
   610     a self-signed certificate, consider the following snippet:
       
   611 
       
   612     \snippet doc/src/snippets/code/src_network_access_qnetworkreply.cpp 0
       
   613 
       
   614     Multiple calls to this function will replace the list of errors that
       
   615     were passed in previous calls.
       
   616     You can clear the list of errors you want to ignore by calling this
       
   617     function with an empty list.
       
   618 
       
   619     \sa sslConfiguration(), sslErrors(), QSslSocket::ignoreSslErrors()
       
   620 */
       
   621 void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)
       
   622 {
       
   623     // do this cryptic trick, because we could not add a virtual method to this class later on
       
   624     // since that breaks binary compatibility
       
   625     int id = metaObject()->indexOfMethod("ignoreSslErrorsImplementation(QList<QSslError>)");
       
   626     if (id != -1) {
       
   627         QList<QSslError> copy(errors);
       
   628         void *arr[] = { 0, &copy };
       
   629         qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
       
   630     }
       
   631 }
       
   632 #endif
       
   633 
       
   634 /*!
       
   635     If this function is called, SSL errors related to network
       
   636     connection will be ignored, including certificate validation
       
   637     errors.
       
   638 
       
   639     Note that calling this function without restraint may pose a
       
   640     security risk for your application. Use it with care.
       
   641 
       
   642     This function can be called from the slot connected to the
       
   643     sslErrors() signal, which indicates which errors were
       
   644     found.
       
   645 
       
   646     \sa sslConfiguration(), sslErrors(), QSslSocket::ignoreSslErrors()
       
   647 */
       
   648 void QNetworkReply::ignoreSslErrors()
       
   649 {
       
   650 }
       
   651 
       
   652 /*!
       
   653     \internal
       
   654 */
       
   655 qint64 QNetworkReply::writeData(const char *, qint64)
       
   656 {
       
   657     return -1;                  // you can't write
       
   658 }
       
   659 
       
   660 /*!
       
   661     Sets the associated operation for this object to be \a
       
   662     operation. This value will be returned by operation().
       
   663 
       
   664     Note: the operation should be set when this object is created and
       
   665     not changed again.
       
   666 
       
   667     \sa operation(), setRequest()
       
   668 */
       
   669 void QNetworkReply::setOperation(QNetworkAccessManager::Operation operation)
       
   670 {
       
   671     Q_D(QNetworkReply);
       
   672     d->operation = operation;
       
   673 }
       
   674 
       
   675 /*!
       
   676     Sets the associated request for this object to be \a request. This
       
   677     value will be returned by request().
       
   678 
       
   679     Note: the request should be set when this object is created and
       
   680     not changed again.
       
   681 
       
   682     \sa request(), setOperation()
       
   683 */
       
   684 void QNetworkReply::setRequest(const QNetworkRequest &request)
       
   685 {
       
   686     Q_D(QNetworkReply);
       
   687     d->request = request;
       
   688 }
       
   689 
       
   690 /*!
       
   691     Sets the error condition to be \a errorCode. The human-readable
       
   692     message is set with \a errorString.
       
   693 
       
   694     Calling setError() does not emit the error(QNetworkReply::NetworkError)
       
   695     signal.
       
   696 
       
   697     \sa error(), errorString()
       
   698 */
       
   699 void QNetworkReply::setError(NetworkError errorCode, const QString &errorString)
       
   700 {
       
   701     Q_D(QNetworkReply);
       
   702     d->errorCode = errorCode;
       
   703     setErrorString(errorString); // in QIODevice
       
   704 }
       
   705 
       
   706 /*!
       
   707     Sets the URL being processed to be \a url. Normally, the URL
       
   708     matches that of the request that was posted, but for a variety of
       
   709     reasons it can be different (for example, a file path being made
       
   710     absolute or canonical).
       
   711 
       
   712     \sa url(), request(), QNetworkRequest::url()
       
   713 */
       
   714 void QNetworkReply::setUrl(const QUrl &url)
       
   715 {
       
   716     Q_D(QNetworkReply);
       
   717     d->url = url;
       
   718 }
       
   719 
       
   720 /*!
       
   721     Sets the known header \a header to be of value \a value. The
       
   722     corresponding raw form of the header will be set as well.
       
   723 
       
   724     \sa header(), setRawHeader(), QNetworkRequest::setHeader()
       
   725 */
       
   726 void QNetworkReply::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
       
   727 {
       
   728     Q_D(QNetworkReply);
       
   729     d->setCookedHeader(header, value);
       
   730 }
       
   731 
       
   732 /*!
       
   733     Sets the raw header \a headerName to be of value \a value. If \a
       
   734     headerName was previously set, it is overridden. Multiple HTTP
       
   735     headers of the same name are functionally equivalent to one single
       
   736     header with the values concatenated, separated by commas.
       
   737 
       
   738     If \a headerName matches a known header, the value \a value will
       
   739     be parsed and the corresponding parsed form will also be set.
       
   740 
       
   741     \sa rawHeader(), header(), setHeader(), QNetworkRequest::setRawHeader()
       
   742 */
       
   743 void QNetworkReply::setRawHeader(const QByteArray &headerName, const QByteArray &value)
       
   744 {
       
   745     Q_D(QNetworkReply);
       
   746     d->setRawHeader(headerName, value);
       
   747 }
       
   748 
       
   749 /*!
       
   750     Sets the attribute \a code to have value \a value. If \a code was
       
   751     previously set, it will be overridden. If \a value is an invalid
       
   752     QVariant, the attribute will be unset.
       
   753 
       
   754     \sa attribute(), QNetworkRequest::setAttribute()
       
   755 */
       
   756 void QNetworkReply::setAttribute(QNetworkRequest::Attribute code, const QVariant &value)
       
   757 {
       
   758     Q_D(QNetworkReply);
       
   759     if (value.isValid())
       
   760         d->attributes.insert(code, value);
       
   761     else
       
   762         d->attributes.remove(code);
       
   763 }
       
   764 
       
   765 QT_END_NAMESPACE