| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qnetworkrequest.h" | - |
| 43 | #include "qnetworkrequest_p.h" | - |
| 44 | #include "qplatformdefs.h" | - |
| 45 | #include "qnetworkcookie.h" | - |
| 46 | #include "qsslconfiguration.h" | - |
| 47 | #include "QtCore/qshareddata.h" | - |
| 48 | #include "QtCore/qlocale.h" | - |
| 49 | #include "QtCore/qdatetime.h" | - |
| 50 | | - |
| 51 | #include <ctype.h> | - |
| 52 | #ifndef QT_NO_DATESTRING | - |
| 53 | # include <stdio.h> | - |
| 54 | #endif | - |
| 55 | | - |
| 56 | QT_BEGIN_NAMESPACE | - |
| 57 | | - |
| 58 | /*! | - |
| 59 | \class QNetworkRequest | - |
| 60 | \since 4.4 | - |
| 61 | \ingroup network | - |
| 62 | \ingroup shared | - |
| 63 | \inmodule QtNetwork | - |
| 64 | | - |
| 65 | \brief The QNetworkRequest class holds a request to be sent with QNetworkAccessManager. | - |
| 66 | | - |
| 67 | QNetworkRequest is part of the Network Access API and is the class | - |
| 68 | holding the information necessary to send a request over the | - |
| 69 | network. It contains a URL and some ancillary information that can | - |
| 70 | be used to modify the request. | - |
| 71 | | - |
| 72 | \sa QNetworkReply, QNetworkAccessManager | - |
| 73 | */ | - |
| 74 | | - |
| 75 | /*! | - |
| 76 | \enum QNetworkRequest::KnownHeaders | - |
| 77 | | - |
| 78 | List of known header types that QNetworkRequest parses. Each known | - |
| 79 | header is also represented in raw form with its full HTTP name. | - |
| 80 | | - |
| 81 | \value ContentDispositionHeader Corresponds to the HTTP | - |
| 82 | Content-Disposition header and contains a string containing the | - |
| 83 | disposition type (for instance, attachment) and a parameter (for | - |
| 84 | instance, filename). | - |
| 85 | | - |
| 86 | \value ContentTypeHeader Corresponds to the HTTP Content-Type | - |
| 87 | header and contains a string containing the media (MIME) type and | - |
| 88 | any auxiliary data (for instance, charset). | - |
| 89 | | - |
| 90 | \value ContentLengthHeader Corresponds to the HTTP Content-Length | - |
| 91 | header and contains the length in bytes of the data transmitted. | - |
| 92 | | - |
| 93 | \value LocationHeader Corresponds to the HTTP Location | - |
| 94 | header and contains a URL representing the actual location of the | - |
| 95 | data, including the destination URL in case of redirections. | - |
| 96 | | - |
| 97 | \value LastModifiedHeader Corresponds to the HTTP Last-Modified | - |
| 98 | header and contains a QDateTime representing the last modification | - |
| 99 | date of the contents. | - |
| 100 | | - |
| 101 | \value CookieHeader Corresponds to the HTTP Cookie header | - |
| 102 | and contains a QList<QNetworkCookie> representing the cookies to | - |
| 103 | be sent back to the server. | - |
| 104 | | - |
| 105 | \value SetCookieHeader Corresponds to the HTTP Set-Cookie | - |
| 106 | header and contains a QList<QNetworkCookie> representing the | - |
| 107 | cookies sent by the server to be stored locally. | - |
| 108 | | - |
| 109 | \value UserAgentHeader The User-Agent header sent by HTTP clients. | - |
| 110 | | - |
| 111 | \value ServerHeader The Server header received by HTTP clients. | - |
| 112 | | - |
| 113 | \sa header(), setHeader(), rawHeader(), setRawHeader() | - |
| 114 | */ | - |
| 115 | | - |
| 116 | /*! | - |
| 117 | \enum QNetworkRequest::Attribute | - |
| 118 | \since 4.7 | - |
| 119 | | - |
| 120 | Attribute codes for the QNetworkRequest and QNetworkReply. | - |
| 121 | | - |
| 122 | Attributes are extra meta-data that are used to control the | - |
| 123 | behavior of the request and to pass further information from the | - |
| 124 | reply back to the application. Attributes are also extensible, | - |
| 125 | allowing custom implementations to pass custom values. | - |
| 126 | | - |
| 127 | The following table explains what the default attribute codes are, | - |
| 128 | the QVariant types associated, the default value if said attribute | - |
| 129 | is missing and whether it's used in requests or replies. | - |
| 130 | | - |
| 131 | \value HttpStatusCodeAttribute | - |
| 132 | Replies only, type: QMetaType::Int (no default) | - |
| 133 | Indicates the HTTP status code received from the HTTP server | - |
| 134 | (like 200, 304, 404, 401, etc.). If the connection was not | - |
| 135 | HTTP-based, this attribute will not be present. | - |
| 136 | | - |
| 137 | \value HttpReasonPhraseAttribute | - |
| 138 | Replies only, type: QMetaType::QByteArray (no default) | - |
| 139 | Indicates the HTTP reason phrase as received from the HTTP | - |
| 140 | server (like "Ok", "Found", "Not Found", "Access Denied", | - |
| 141 | etc.) This is the human-readable representation of the status | - |
| 142 | code (see above). If the connection was not HTTP-based, this | - |
| 143 | attribute will not be present. | - |
| 144 | | - |
| 145 | \value RedirectionTargetAttribute | - |
| 146 | Replies only, type: QMetaType::QUrl (no default) | - |
| 147 | If present, it indicates that the server is redirecting the | - |
| 148 | request to a different URL. The Network Access API does not by | - |
| 149 | default follow redirections: it's up to the application to | - |
| 150 | determine if the requested redirection should be allowed, | - |
| 151 | according to its security policies. | - |
| 152 | The returned URL might be relative. Use QUrl::resolved() | - |
| 153 | to create an absolute URL out of it. | - |
| 154 | | - |
| 155 | \value ConnectionEncryptedAttribute | - |
| 156 | Replies only, type: QMetaType::Bool (default: false) | - |
| 157 | Indicates whether the data was obtained through an encrypted | - |
| 158 | (secure) connection. | - |
| 159 | | - |
| 160 | \value CacheLoadControlAttribute | - |
| 161 | Requests only, type: QMetaType::Int (default: QNetworkRequest::PreferNetwork) | - |
| 162 | Controls how the cache should be accessed. The possible values | - |
| 163 | are those of QNetworkRequest::CacheLoadControl. Note that the | - |
| 164 | default QNetworkAccessManager implementation does not support | - |
| 165 | caching. However, this attribute may be used by certain | - |
| 166 | backends to modify their requests (for example, for caching proxies). | - |
| 167 | | - |
| 168 | \value CacheSaveControlAttribute | - |
| 169 | Requests only, type: QMetaType::Bool (default: true) | - |
| 170 | Controls if the data obtained should be saved to cache for | - |
| 171 | future uses. If the value is false, the data obtained will not | - |
| 172 | be automatically cached. If true, data may be cached, provided | - |
| 173 | it is cacheable (what is cacheable depends on the protocol | - |
| 174 | being used). | - |
| 175 | | - |
| 176 | \value SourceIsFromCacheAttribute | - |
| 177 | Replies only, type: QMetaType::Bool (default: false) | - |
| 178 | Indicates whether the data was obtained from cache | - |
| 179 | or not. | - |
| 180 | | - |
| 181 | \value DoNotBufferUploadDataAttribute | - |
| 182 | Requests only, type: QMetaType::Bool (default: false) | - |
| 183 | Indicates whether the QNetworkAccessManager code is | - |
| 184 | allowed to buffer the upload data, e.g. when doing a HTTP POST. | - |
| 185 | When using this flag with sequential upload data, the ContentLengthHeader | - |
| 186 | header must be set. | - |
| 187 | | - |
| 188 | \value HttpPipeliningAllowedAttribute | - |
| 189 | Requests only, type: QMetaType::Bool (default: false) | - |
| 190 | Indicates whether the QNetworkAccessManager code is | - |
| 191 | allowed to use HTTP pipelining with this request. | - |
| 192 | | - |
| 193 | \value HttpPipeliningWasUsedAttribute | - |
| 194 | Replies only, type: QMetaType::Bool | - |
| 195 | Indicates whether the HTTP pipelining was used for receiving | - |
| 196 | this reply. | - |
| 197 | | - |
| 198 | \value CustomVerbAttribute | - |
| 199 | Requests only, type: QMetaType::QByteArray | - |
| 200 | Holds the value for the custom HTTP verb to send (destined for usage | - |
| 201 | of other verbs than GET, POST, PUT and DELETE). This verb is set | - |
| 202 | when calling QNetworkAccessManager::sendCustomRequest(). | - |
| 203 | | - |
| 204 | \value CookieLoadControlAttribute | - |
| 205 | Requests only, type: QMetaType::Int (default: QNetworkRequest::Automatic) | - |
| 206 | Indicates whether to send 'Cookie' headers in the request. | - |
| 207 | This attribute is set to false by Qt WebKit when creating a cross-origin | - |
| 208 | XMLHttpRequest where withCredentials has not been set explicitly to true by the | - |
| 209 | Javascript that created the request. | - |
| 210 | See \l{http://www.w3.org/TR/XMLHttpRequest2/#credentials-flag}{here} for more information. | - |
| 211 | (This value was introduced in 4.7.) | - |
| 212 | | - |
| 213 | \value CookieSaveControlAttribute | - |
| 214 | Requests only, type: QMetaType::Int (default: QNetworkRequest::Automatic) | - |
| 215 | Indicates whether to save 'Cookie' headers received from the server in reply | - |
| 216 | to the request. | - |
| 217 | This attribute is set to false by Qt WebKit when creating a cross-origin | - |
| 218 | XMLHttpRequest where withCredentials has not been set explicitly to true by the | - |
| 219 | Javascript that created the request. | - |
| 220 | See \l{http://www.w3.org/TR/XMLHttpRequest2/#credentials-flag} {here} for more information. | - |
| 221 | (This value was introduced in 4.7.) | - |
| 222 | | - |
| 223 | \value AuthenticationReuseAttribute | - |
| 224 | Requests only, type: QMetaType::Int (default: QNetworkRequest::Automatic) | - |
| 225 | Indicates whether to use cached authorization credentials in the request, | - |
| 226 | if available. If this is set to QNetworkRequest::Manual and the authentication | - |
| 227 | mechanism is 'Basic' or 'Digest', Qt will not send an an 'Authorization' HTTP | - |
| 228 | header with any cached credentials it may have for the request's URL. | - |
| 229 | This attribute is set to QNetworkRequest::Manual by Qt WebKit when creating a cross-origin | - |
| 230 | XMLHttpRequest where withCredentials has not been set explicitly to true by the | - |
| 231 | Javascript that created the request. | - |
| 232 | See \l{http://www.w3.org/TR/XMLHttpRequest2/#credentials-flag} {here} for more information. | - |
| 233 | (This value was introduced in 4.7.) | - |
| 234 | | - |
| 235 | \omitvalue MaximumDownloadBufferSizeAttribute | - |
| 236 | | - |
| 237 | \omitvalue DownloadBufferAttribute | - |
| 238 | | - |
| 239 | \omitvalue SynchronousRequestAttribute | - |
| 240 | | - |
| 241 | \value BackgroundRequestAttribute | - |
| 242 | Type: QMetaType::Bool (default: false) | - |
| 243 | Indicates that this is a background transfer, rather than a user initiated | - |
| 244 | transfer. Depending on the platform, background transfers may be subject | - |
| 245 | to different policies. | - |
| 246 | The QNetworkSession ConnectInBackground property will be set according to | - |
| 247 | this attribute. | - |
| 248 | | - |
| 249 | \value User | - |
| 250 | Special type. Additional information can be passed in | - |
| 251 | QVariants with types ranging from User to UserMax. The default | - |
| 252 | implementation of Network Access will ignore any request | - |
| 253 | attributes in this range and it will not produce any | - |
| 254 | attributes in this range in replies. The range is reserved for | - |
| 255 | extensions of QNetworkAccessManager. | - |
| 256 | | - |
| 257 | \value UserMax | - |
| 258 | Special type. See User. | - |
| 259 | */ | - |
| 260 | | - |
| 261 | /*! | - |
| 262 | \enum QNetworkRequest::CacheLoadControl | - |
| 263 | | - |
| 264 | Controls the caching mechanism of QNetworkAccessManager. | - |
| 265 | | - |
| 266 | \value AlwaysNetwork always load from network and do not | - |
| 267 | check if the cache has a valid entry (similar to the | - |
| 268 | "Reload" feature in browsers); in addition, force intermediate | - |
| 269 | caches to re-validate. | - |
| 270 | | - |
| 271 | \value PreferNetwork default value; load from the network | - |
| 272 | if the cached entry is older than the network entry. This will never | - |
| 273 | return stale data from the cache, but revalidate resources that | - |
| 274 | have become stale. | - |
| 275 | | - |
| 276 | \value PreferCache load from cache if available, | - |
| 277 | otherwise load from network. Note that this can return possibly | - |
| 278 | stale (but not expired) items from cache. | - |
| 279 | | - |
| 280 | \value AlwaysCache only load from cache, indicating error | - |
| 281 | if the item was not cached (i.e., off-line mode) | - |
| 282 | */ | - |
| 283 | | - |
| 284 | /*! | - |
| 285 | \enum QNetworkRequest::LoadControl | - |
| 286 | \since 4.7 | - |
| 287 | | - |
| 288 | Indicates if an aspect of the request's loading mechanism has been | - |
| 289 | manually overridden, e.g. by Qt WebKit. | - |
| 290 | | - |
| 291 | \value Automatic default value: indicates default behaviour. | - |
| 292 | | - |
| 293 | \value Manual indicates behaviour has been manually overridden. | - |
| 294 | */ | - |
| 295 | | - |
| 296 | class QNetworkRequestPrivate: public QSharedData, public QNetworkHeadersPrivate | - |
| 297 | { | - |
| 298 | public: | - |
| 299 | inline QNetworkRequestPrivate() | - |
| 300 | : priority(QNetworkRequest::NormalPriority) | - |
| 301 | #ifndef QT_NO_SSL | - |
| 302 | , sslConfiguration(0) | - |
| 303 | #endif | - |
| 304 | { qRegisterMetaType<QNetworkRequest>(); } executed: }Execution Count:1694 | 1694 |
| 305 | ~QNetworkRequestPrivate() | - |
| 306 | { | - |
| 307 | #ifndef QT_NO_SSL | - |
| 308 | delete sslConfiguration; executed (the execution status of this line is deduced): delete sslConfiguration; | - |
| 309 | #endif | - |
| 310 | } executed: }Execution Count:1911 | 1911 |
| 311 | | - |
| 312 | | - |
| 313 | QNetworkRequestPrivate(const QNetworkRequestPrivate &other) | - |
| 314 | : QSharedData(other), QNetworkHeadersPrivate(other) | - |
| 315 | { | - |
| 316 | url = other.url; executed (the execution status of this line is deduced): url = other.url; | - |
| 317 | priority = other.priority; executed (the execution status of this line is deduced): priority = other.priority; | - |
| 318 | | - |
| 319 | #ifndef QT_NO_SSL | - |
| 320 | sslConfiguration = 0; executed (the execution status of this line is deduced): sslConfiguration = 0; | - |
| 321 | if (other.sslConfiguration) evaluated: other.sslConfiguration| yes Evaluation Count:95 | yes Evaluation Count:122 |
| 95-122 |
| 322 | sslConfiguration = new QSslConfiguration(*other.sslConfiguration); executed: sslConfiguration = new QSslConfiguration(*other.sslConfiguration);Execution Count:95 | 95 |
| 323 | #endif | - |
| 324 | } executed: }Execution Count:217 | 217 |
| 325 | | - |
| 326 | inline bool operator==(const QNetworkRequestPrivate &other) const | - |
| 327 | { | - |
| 328 | return url == other.url && never executed: return url == other.url && priority == other.priority && rawHeaders == other.rawHeaders && attributes == other.attributes; | 0 |
| 329 | priority == other.priority && never executed: return url == other.url && priority == other.priority && rawHeaders == other.rawHeaders && attributes == other.attributes; | 0 |
| 330 | rawHeaders == other.rawHeaders && never executed: return url == other.url && priority == other.priority && rawHeaders == other.rawHeaders && attributes == other.attributes; | 0 |
| 331 | attributes == other.attributes; never executed: return url == other.url && priority == other.priority && rawHeaders == other.rawHeaders && attributes == other.attributes; | 0 |
| 332 | // don't compare cookedHeaders | - |
| 333 | } | - |
| 334 | | - |
| 335 | QUrl url; | - |
| 336 | QNetworkRequest::Priority priority; | - |
| 337 | #ifndef QT_NO_SSL | - |
| 338 | mutable QSslConfiguration *sslConfiguration; | - |
| 339 | #endif | - |
| 340 | }; | - |
| 341 | | - |
| 342 | /*! | - |
| 343 | Constructs a QNetworkRequest object with \a url as the URL to be | - |
| 344 | requested. | - |
| 345 | | - |
| 346 | \sa url(), setUrl() | - |
| 347 | */ | - |
| 348 | QNetworkRequest::QNetworkRequest(const QUrl &url) | - |
| 349 | : d(new QNetworkRequestPrivate) | - |
| 350 | { | - |
| 351 | d->url = url; executed (the execution status of this line is deduced): d->url = url; | - |
| 352 | } executed: }Execution Count:1694 | 1694 |
| 353 | | - |
| 354 | /*! | - |
| 355 | Creates a copy of \a other. | - |
| 356 | */ | - |
| 357 | QNetworkRequest::QNetworkRequest(const QNetworkRequest &other) | - |
| 358 | : d(other.d) | - |
| 359 | { | - |
| 360 | } executed: }Execution Count:929 | 929 |
| 361 | | - |
| 362 | /*! | - |
| 363 | Disposes of the QNetworkRequest object. | - |
| 364 | */ | - |
| 365 | QNetworkRequest::~QNetworkRequest() | - |
| 366 | { | - |
| 367 | // QSharedDataPointer auto deletes | - |
| 368 | d = 0; executed (the execution status of this line is deduced): d = 0; | - |
| 369 | } executed: }Execution Count:2623 | 2623 |
| 370 | | - |
| 371 | /*! | - |
| 372 | Returns true if this object is the same as \a other (i.e., if they | - |
| 373 | have the same URL, same headers and same meta-data settings). | - |
| 374 | | - |
| 375 | \sa operator!=() | - |
| 376 | */ | - |
| 377 | bool QNetworkRequest::operator==(const QNetworkRequest &other) const | - |
| 378 | { | - |
| 379 | return d == other.d || *d == *other.d; executed: return d == other.d || *d == *other.d;Execution Count:1 | 1 |
| 380 | } | - |
| 381 | | - |
| 382 | /*! | - |
| 383 | \fn bool QNetworkRequest::operator!=(const QNetworkRequest &other) const | - |
| 384 | | - |
| 385 | Returns false if this object is not the same as \a other. | - |
| 386 | | - |
| 387 | \sa operator==() | - |
| 388 | */ | - |
| 389 | | - |
| 390 | /*! | - |
| 391 | Creates a copy of \a other | - |
| 392 | */ | - |
| 393 | QNetworkRequest &QNetworkRequest::operator=(const QNetworkRequest &other) | - |
| 394 | { | - |
| 395 | d = other.d; executed (the execution status of this line is deduced): d = other.d; | - |
| 396 | return *this; executed: return *this;Execution Count:874 | 874 |
| 397 | } | - |
| 398 | | - |
| 399 | /*! | - |
| 400 | \fn void QNetworkRequest::swap(QNetworkRequest &other) | - |
| 401 | \since 5.0 | - |
| 402 | | - |
| 403 | Swaps this network request with \a other. This function is very | - |
| 404 | fast and never fails. | - |
| 405 | */ | - |
| 406 | | - |
| 407 | /*! | - |
| 408 | Returns the URL this network request is referring to. | - |
| 409 | | - |
| 410 | \sa setUrl() | - |
| 411 | */ | - |
| 412 | QUrl QNetworkRequest::url() const | - |
| 413 | { | - |
| 414 | return d->url; executed: return d->url;Execution Count:5035 | 5035 |
| 415 | } | - |
| 416 | | - |
| 417 | /*! | - |
| 418 | Sets the URL this network request is referring to be \a url. | - |
| 419 | | - |
| 420 | \sa url() | - |
| 421 | */ | - |
| 422 | void QNetworkRequest::setUrl(const QUrl &url) | - |
| 423 | { | - |
| 424 | d->url = url; executed (the execution status of this line is deduced): d->url = url; | - |
| 425 | } executed: }Execution Count:24 | 24 |
| 426 | | - |
| 427 | /*! | - |
| 428 | Returns the value of the known network header \a header if it is | - |
| 429 | present in this request. If it is not present, returns QVariant() | - |
| 430 | (i.e., an invalid variant). | - |
| 431 | | - |
| 432 | \sa KnownHeaders, rawHeader(), setHeader() | - |
| 433 | */ | - |
| 434 | QVariant QNetworkRequest::header(KnownHeaders header) const | - |
| 435 | { | - |
| 436 | return d->cookedHeaders.value(header); executed: return d->cookedHeaders.value(header);Execution Count:889 | 889 |
| 437 | } | - |
| 438 | | - |
| 439 | /*! | - |
| 440 | Sets the value of the known header \a header to be \a value, | - |
| 441 | overriding any previously set headers. This operation also sets | - |
| 442 | the equivalent raw HTTP header. | - |
| 443 | | - |
| 444 | \sa KnownHeaders, setRawHeader(), header() | - |
| 445 | */ | - |
| 446 | void QNetworkRequest::setHeader(KnownHeaders header, const QVariant &value) | - |
| 447 | { | - |
| 448 | d->setCookedHeader(header, value); executed (the execution status of this line is deduced): d->setCookedHeader(header, value); | - |
| 449 | } executed: }Execution Count:182 | 182 |
| 450 | | - |
| 451 | /*! | - |
| 452 | Returns true if the raw header \a headerName is present in this | - |
| 453 | network request. | - |
| 454 | | - |
| 455 | \sa rawHeader(), setRawHeader() | - |
| 456 | */ | - |
| 457 | bool QNetworkRequest::hasRawHeader(const QByteArray &headerName) const | - |
| 458 | { | - |
| 459 | return d->findRawHeader(headerName) != d->rawHeaders.constEnd(); executed: return d->findRawHeader(headerName) != d->rawHeaders.constEnd();Execution Count:605 | 605 |
| 460 | } | - |
| 461 | | - |
| 462 | /*! | - |
| 463 | Returns the raw form of header \a headerName. If no such header is | - |
| 464 | present, an empty QByteArray is returned, which may be | - |
| 465 | indistinguishable from a header that is present but has no content | - |
| 466 | (use hasRawHeader() to find out if the header exists or not). | - |
| 467 | | - |
| 468 | Raw headers can be set with setRawHeader() or with setHeader(). | - |
| 469 | | - |
| 470 | \sa header(), setRawHeader() | - |
| 471 | */ | - |
| 472 | QByteArray QNetworkRequest::rawHeader(const QByteArray &headerName) const | - |
| 473 | { | - |
| 474 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator it = executed (the execution status of this line is deduced): QNetworkHeadersPrivate::RawHeadersList::ConstIterator it = | - |
| 475 | d->findRawHeader(headerName); executed (the execution status of this line is deduced): d->findRawHeader(headerName); | - |
| 476 | if (it != d->rawHeaders.constEnd()) evaluated: it != d->rawHeaders.constEnd()| yes Evaluation Count:352 | yes Evaluation Count:4 |
| 4-352 |
| 477 | return it->second; executed: return it->second;Execution Count:352 | 352 |
| 478 | return QByteArray(); executed: return QByteArray();Execution Count:4 | 4 |
| 479 | } | - |
| 480 | | - |
| 481 | /*! | - |
| 482 | Returns a list of all raw headers that are set in this network | - |
| 483 | request. The list is in the order that the headers were set. | - |
| 484 | | - |
| 485 | \sa hasRawHeader(), rawHeader() | - |
| 486 | */ | - |
| 487 | QList<QByteArray> QNetworkRequest::rawHeaderList() const | - |
| 488 | { | - |
| 489 | return d->rawHeadersKeys(); executed: return d->rawHeadersKeys();Execution Count:712 | 712 |
| 490 | } | - |
| 491 | | - |
| 492 | /*! | - |
| 493 | Sets the header \a headerName to be of value \a headerValue. If \a | - |
| 494 | headerName corresponds to a known header (see | - |
| 495 | QNetworkRequest::KnownHeaders), the raw format will be parsed and | - |
| 496 | the corresponding "cooked" header will be set as well. | - |
| 497 | | - |
| 498 | For example: | - |
| 499 | \snippet code/src_network_access_qnetworkrequest.cpp 0 | - |
| 500 | | - |
| 501 | will also set the known header LastModifiedHeader to be the | - |
| 502 | QDateTime object of the parsed date. | - |
| 503 | | - |
| 504 | Note: setting the same header twice overrides the previous | - |
| 505 | setting. To accomplish the behaviour of multiple HTTP headers of | - |
| 506 | the same name, you should concatenate the two values, separating | - |
| 507 | them with a comma (",") and set one single raw header. | - |
| 508 | | - |
| 509 | \sa KnownHeaders, setHeader(), hasRawHeader(), rawHeader() | - |
| 510 | */ | - |
| 511 | void QNetworkRequest::setRawHeader(const QByteArray &headerName, const QByteArray &headerValue) | - |
| 512 | { | - |
| 513 | d->setRawHeader(headerName, headerValue); executed (the execution status of this line is deduced): d->setRawHeader(headerName, headerValue); | - |
| 514 | } executed: }Execution Count:197 | 197 |
| 515 | | - |
| 516 | /*! | - |
| 517 | Returns the attribute associated with the code \a code. If the | - |
| 518 | attribute has not been set, it returns \a defaultValue. | - |
| 519 | | - |
| 520 | Note: this function does not apply the defaults listed in | - |
| 521 | QNetworkRequest::Attribute. | - |
| 522 | | - |
| 523 | \sa setAttribute(), QNetworkRequest::Attribute | - |
| 524 | */ | - |
| 525 | QVariant QNetworkRequest::attribute(Attribute code, const QVariant &defaultValue) const | - |
| 526 | { | - |
| 527 | return d->attributes.value(code, defaultValue); executed: return d->attributes.value(code, defaultValue);Execution Count:6336 | 6336 |
| 528 | } | - |
| 529 | | - |
| 530 | /*! | - |
| 531 | Sets the attribute associated with code \a code to be value \a | - |
| 532 | value. If the attribute is already set, the previous value is | - |
| 533 | discarded. In special, if \a value is an invalid QVariant, the | - |
| 534 | attribute is unset. | - |
| 535 | | - |
| 536 | \sa attribute(), QNetworkRequest::Attribute | - |
| 537 | */ | - |
| 538 | void QNetworkRequest::setAttribute(Attribute code, const QVariant &value) | - |
| 539 | { | - |
| 540 | if (value.isValid()) partially evaluated: value.isValid()| yes Evaluation Count:195 | no Evaluation Count:0 |
| 0-195 |
| 541 | d->attributes.insert(code, value); executed: d->attributes.insert(code, value);Execution Count:195 | 195 |
| 542 | else | - |
| 543 | d->attributes.remove(code); never executed: d->attributes.remove(code); | 0 |
| 544 | } | - |
| 545 | | - |
| 546 | #ifndef QT_NO_SSL | - |
| 547 | /*! | - |
| 548 | Returns this network request's SSL configuration. By default, no | - |
| 549 | SSL settings are specified. | - |
| 550 | | - |
| 551 | \sa setSslConfiguration() | - |
| 552 | */ | - |
| 553 | QSslConfiguration QNetworkRequest::sslConfiguration() const | - |
| 554 | { | - |
| 555 | if (!d->sslConfiguration) evaluated: !d->sslConfiguration| yes Evaluation Count:645 | yes Evaluation Count:244 |
| 244-645 |
| 556 | d->sslConfiguration = new QSslConfiguration(QSslConfiguration::defaultConfiguration()); executed: d->sslConfiguration = new QSslConfiguration(QSslConfiguration::defaultConfiguration());Execution Count:645 | 645 |
| 557 | return *d->sslConfiguration; executed: return *d->sslConfiguration;Execution Count:889 | 889 |
| 558 | } | - |
| 559 | | - |
| 560 | /*! | - |
| 561 | Sets this network request's SSL configuration to be \a config. The | - |
| 562 | settings that apply are the private key, the local certificate, | - |
| 563 | the SSL protocol (SSLv2, SSLv3, TLSv1.0 where applicable), the CA | - |
| 564 | certificates and the ciphers that the SSL backend is allowed to | - |
| 565 | use. | - |
| 566 | | - |
| 567 | By default, no SSL configuration is set, which allows the backends | - |
| 568 | to choose freely what configuration is best for them. | - |
| 569 | | - |
| 570 | \sa sslConfiguration(), QSslConfiguration::defaultConfiguration() | - |
| 571 | */ | - |
| 572 | void QNetworkRequest::setSslConfiguration(const QSslConfiguration &config) | - |
| 573 | { | - |
| 574 | if (!d->sslConfiguration) partially evaluated: !d->sslConfiguration| yes Evaluation Count:44 | no Evaluation Count:0 |
| 0-44 |
| 575 | d->sslConfiguration = new QSslConfiguration(config); executed: d->sslConfiguration = new QSslConfiguration(config);Execution Count:44 | 44 |
| 576 | else | - |
| 577 | *d->sslConfiguration = config; never executed: *d->sslConfiguration = config; | 0 |
| 578 | } | - |
| 579 | #endif | - |
| 580 | | - |
| 581 | /*! | - |
| 582 | \since 4.6 | - |
| 583 | | - |
| 584 | Allows setting a reference to the \a object initiating | - |
| 585 | the request. | - |
| 586 | | - |
| 587 | For example Qt WebKit sets the originating object to the | - |
| 588 | QWebFrame that initiated the request. | - |
| 589 | | - |
| 590 | \sa originatingObject() | - |
| 591 | */ | - |
| 592 | void QNetworkRequest::setOriginatingObject(QObject *object) | - |
| 593 | { | - |
| 594 | d->originatingObject = object; executed (the execution status of this line is deduced): d->originatingObject = object; | - |
| 595 | } executed: }Execution Count:1 | 1 |
| 596 | | - |
| 597 | /*! | - |
| 598 | \since 4.6 | - |
| 599 | | - |
| 600 | Returns a reference to the object that initiated this | - |
| 601 | network request; returns 0 if not set or the object has | - |
| 602 | been destroyed. | - |
| 603 | | - |
| 604 | \sa setOriginatingObject() | - |
| 605 | */ | - |
| 606 | QObject *QNetworkRequest::originatingObject() const | - |
| 607 | { | - |
| 608 | return d->originatingObject.data(); executed: return d->originatingObject.data();Execution Count:3 | 3 |
| 609 | } | - |
| 610 | | - |
| 611 | /*! | - |
| 612 | \since 4.7 | - |
| 613 | | - |
| 614 | Return the priority of this request. | - |
| 615 | | - |
| 616 | \sa setPriority() | - |
| 617 | */ | - |
| 618 | QNetworkRequest::Priority QNetworkRequest::priority() const | - |
| 619 | { | - |
| 620 | return d->priority; executed: return d->priority;Execution Count:709 | 709 |
| 621 | } | - |
| 622 | | - |
| 623 | /*! \enum QNetworkRequest::Priority | - |
| 624 | | - |
| 625 | \since 4.7 | - |
| 626 | | - |
| 627 | This enum lists the possible network request priorities. | - |
| 628 | | - |
| 629 | \value HighPriority High priority | - |
| 630 | \value NormalPriority Normal priority | - |
| 631 | \value LowPriority Low priority | - |
| 632 | */ | - |
| 633 | | - |
| 634 | /*! | - |
| 635 | \since 4.7 | - |
| 636 | | - |
| 637 | Set the priority of this request to \a priority. | - |
| 638 | | - |
| 639 | \note The \a priority is only a hint to the network access | - |
| 640 | manager. It can use it or not. Currently it is used for HTTP to | - |
| 641 | decide which request should be sent first to a server. | - |
| 642 | | - |
| 643 | \sa priority() | - |
| 644 | */ | - |
| 645 | void QNetworkRequest::setPriority(Priority priority) | - |
| 646 | { | - |
| 647 | d->priority = priority; never executed (the execution status of this line is deduced): d->priority = priority; | - |
| 648 | } | 0 |
| 649 | | - |
| 650 | static QByteArray headerName(QNetworkRequest::KnownHeaders header) | - |
| 651 | { | - |
| 652 | switch (header) { | - |
| 653 | case QNetworkRequest::ContentTypeHeader: | - |
| 654 | return "Content-Type"; executed: return "Content-Type";Execution Count:86 | 86 |
| 655 | | - |
| 656 | case QNetworkRequest::ContentLengthHeader: | - |
| 657 | return "Content-Length"; executed: return "Content-Length";Execution Count:214 | 214 |
| 658 | | - |
| 659 | case QNetworkRequest::LocationHeader: | - |
| 660 | return "Location"; executed: return "Location";Execution Count:3 | 3 |
| 661 | | - |
| 662 | case QNetworkRequest::LastModifiedHeader: | - |
| 663 | return "Last-Modified"; executed: return "Last-Modified";Execution Count:50 | 50 |
| 664 | | - |
| 665 | case QNetworkRequest::CookieHeader: | - |
| 666 | return "Cookie"; executed: return "Cookie";Execution Count:11 | 11 |
| 667 | | - |
| 668 | case QNetworkRequest::SetCookieHeader: | - |
| 669 | return "Set-Cookie"; executed: return "Set-Cookie";Execution Count:3 | 3 |
| 670 | | - |
| 671 | case QNetworkRequest::ContentDispositionHeader: | - |
| 672 | return "Content-Disposition"; executed: return "Content-Disposition";Execution Count:30 | 30 |
| 673 | | - |
| 674 | case QNetworkRequest::UserAgentHeader: | - |
| 675 | return "User-Agent"; executed: return "User-Agent";Execution Count:1 | 1 |
| 676 | | - |
| 677 | case QNetworkRequest::ServerHeader: | - |
| 678 | return "Server"; never executed: return "Server"; | 0 |
| 679 | | - |
| 680 | // no default: | - |
| 681 | // if new values are added, this will generate a compiler warning | - |
| 682 | } | - |
| 683 | | - |
| 684 | return QByteArray(); never executed: return QByteArray(); | 0 |
| 685 | } | - |
| 686 | | - |
| 687 | static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVariant &value) | - |
| 688 | { | - |
| 689 | switch (header) { | - |
| 690 | case QNetworkRequest::ContentTypeHeader: | - |
| 691 | case QNetworkRequest::ContentLengthHeader: | - |
| 692 | case QNetworkRequest::ContentDispositionHeader: | - |
| 693 | case QNetworkRequest::UserAgentHeader: | - |
| 694 | case QNetworkRequest::ServerHeader: | - |
| 695 | return value.toByteArray(); executed: return value.toByteArray();Execution Count:330 | 330 |
| 696 | | - |
| 697 | case QNetworkRequest::LocationHeader: | - |
| 698 | switch (value.userType()) { | - |
| 699 | case QMetaType::QUrl: | - |
| 700 | return value.toUrl().toEncoded(); executed: return value.toUrl().toEncoded();Execution Count:1 | 1 |
| 701 | | - |
| 702 | default: | - |
| 703 | return value.toByteArray(); executed: return value.toByteArray();Execution Count:2 | 2 |
| 704 | } | - |
| 705 | | - |
| 706 | case QNetworkRequest::LastModifiedHeader: code before this statement never executed: case QNetworkRequest::LastModifiedHeader: | 0 |
| 707 | switch (value.userType()) { | - |
| 708 | case QMetaType::QDate: | - |
| 709 | case QMetaType::QDateTime: | - |
| 710 | // generate RFC 1123/822 dates: | - |
| 711 | return QNetworkHeadersPrivate::toHttpDate(value.toDateTime()); executed: return QNetworkHeadersPrivate::toHttpDate(value.toDateTime());Execution Count:48 | 48 |
| 712 | | - |
| 713 | default: | - |
| 714 | return value.toByteArray(); never executed: return value.toByteArray(); | 0 |
| 715 | } | - |
| 716 | | - |
| 717 | case QNetworkRequest::CookieHeader: { | - |
| 718 | QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(value); executed (the execution status of this line is deduced): QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(value); | - |
| 719 | if (cookies.isEmpty() && value.userType() == qMetaTypeId<QNetworkCookie>()) partially evaluated: cookies.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:11 |
never evaluated: value.userType() == qMetaTypeId<QNetworkCookie>() | 0-11 |
| 720 | cookies << qvariant_cast<QNetworkCookie>(value); never executed: cookies << qvariant_cast<QNetworkCookie>(value); | 0 |
| 721 | | - |
| 722 | QByteArray result; executed (the execution status of this line is deduced): QByteArray result; | - |
| 723 | bool first = true; executed (the execution status of this line is deduced): bool first = true; | - |
| 724 | foreach (const QNetworkCookie &cookie, cookies) { executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(cookies)> _container_(cookies); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QNetworkCookie &cookie = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
| 725 | if (!first) evaluated: !first| yes Evaluation Count:3 | yes Evaluation Count:11 |
| 3-11 |
| 726 | result += "; "; executed: result += "; ";Execution Count:3 | 3 |
| 727 | first = false; executed (the execution status of this line is deduced): first = false; | - |
| 728 | result += cookie.toRawForm(QNetworkCookie::NameAndValueOnly); executed (the execution status of this line is deduced): result += cookie.toRawForm(QNetworkCookie::NameAndValueOnly); | - |
| 729 | } executed: }Execution Count:14 | 14 |
| 730 | return result; executed: return result;Execution Count:11 | 11 |
| 731 | } | - |
| 732 | | - |
| 733 | case QNetworkRequest::SetCookieHeader: { | - |
| 734 | QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(value); executed (the execution status of this line is deduced): QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(value); | - |
| 735 | if (cookies.isEmpty() && value.userType() == qMetaTypeId<QNetworkCookie>()) partially evaluated: cookies.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:3 |
never evaluated: value.userType() == qMetaTypeId<QNetworkCookie>() | 0-3 |
| 736 | cookies << qvariant_cast<QNetworkCookie>(value); never executed: cookies << qvariant_cast<QNetworkCookie>(value); | 0 |
| 737 | | - |
| 738 | QByteArray result; executed (the execution status of this line is deduced): QByteArray result; | - |
| 739 | bool first = true; executed (the execution status of this line is deduced): bool first = true; | - |
| 740 | foreach (const QNetworkCookie &cookie, cookies) { executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(cookies)> _container_(cookies); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QNetworkCookie &cookie = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
| 741 | if (!first) evaluated: !first| yes Evaluation Count:1 | yes Evaluation Count:3 |
| 1-3 |
| 742 | result += ", "; executed: result += ", ";Execution Count:1 | 1 |
| 743 | first = false; executed (the execution status of this line is deduced): first = false; | - |
| 744 | result += cookie.toRawForm(QNetworkCookie::Full); executed (the execution status of this line is deduced): result += cookie.toRawForm(QNetworkCookie::Full); | - |
| 745 | } executed: }Execution Count:4 | 4 |
| 746 | return result; executed: return result;Execution Count:3 | 3 |
| 747 | } | - |
| 748 | } | - |
| 749 | | - |
| 750 | return QByteArray(); never executed: return QByteArray(); | 0 |
| 751 | } | - |
| 752 | | - |
| 753 | static QNetworkRequest::KnownHeaders parseHeaderName(const QByteArray &headerName) | - |
| 754 | { | - |
| 755 | // headerName is not empty here | - |
| 756 | | - |
| 757 | switch (tolower(headerName.at(0))) { | - |
| 758 | case 'c': | - |
| 759 | if (qstricmp(headerName.constData(), "content-type") == 0) evaluated: qstricmp(headerName.constData(), "content-type") == 0| yes Evaluation Count:766 | yes Evaluation Count:1157 |
| 766-1157 |
| 760 | return QNetworkRequest::ContentTypeHeader; executed: return QNetworkRequest::ContentTypeHeader;Execution Count:766 | 766 |
| 761 | else if (qstricmp(headerName.constData(), "content-length") == 0) evaluated: qstricmp(headerName.constData(), "content-length") == 0| yes Evaluation Count:521 | yes Evaluation Count:636 |
| 521-636 |
| 762 | return QNetworkRequest::ContentLengthHeader; executed: return QNetworkRequest::ContentLengthHeader;Execution Count:521 | 521 |
| 763 | else if (qstricmp(headerName.constData(), "cookie") == 0) evaluated: qstricmp(headerName.constData(), "cookie") == 0| yes Evaluation Count:2 | yes Evaluation Count:634 |
| 2-634 |
| 764 | return QNetworkRequest::CookieHeader; executed: return QNetworkRequest::CookieHeader;Execution Count:2 | 2 |
| 765 | break; executed: break;Execution Count:634 | 634 |
| 766 | | - |
| 767 | case 'l': | - |
| 768 | if (qstricmp(headerName.constData(), "location") == 0) evaluated: qstricmp(headerName.constData(), "location") == 0| yes Evaluation Count:38 | yes Evaluation Count:277 |
| 38-277 |
| 769 | return QNetworkRequest::LocationHeader; executed: return QNetworkRequest::LocationHeader;Execution Count:38 | 38 |
| 770 | else if (qstricmp(headerName.constData(), "last-modified") == 0) partially evaluated: qstricmp(headerName.constData(), "last-modified") == 0| yes Evaluation Count:277 | no Evaluation Count:0 |
| 0-277 |
| 771 | return QNetworkRequest::LastModifiedHeader; executed: return QNetworkRequest::LastModifiedHeader;Execution Count:277 | 277 |
| 772 | break; | 0 |
| 773 | | - |
| 774 | case 's': | - |
| 775 | if (qstricmp(headerName.constData(), "set-cookie") == 0) evaluated: qstricmp(headerName.constData(), "set-cookie") == 0| yes Evaluation Count:17 | yes Evaluation Count:686 |
| 17-686 |
| 776 | return QNetworkRequest::SetCookieHeader; executed: return QNetworkRequest::SetCookieHeader;Execution Count:17 | 17 |
| 777 | else if (qstricmp(headerName.constData(), "server") == 0) partially evaluated: qstricmp(headerName.constData(), "server") == 0| yes Evaluation Count:686 | no Evaluation Count:0 |
| 0-686 |
| 778 | return QNetworkRequest::ServerHeader; executed: return QNetworkRequest::ServerHeader;Execution Count:686 | 686 |
| 779 | break; | 0 |
| 780 | | - |
| 781 | case 'u': | - |
| 782 | if (qstricmp(headerName.constData(), "user-agent") == 0) partially evaluated: qstricmp(headerName.constData(), "user-agent") == 0| yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-8 |
| 783 | return QNetworkRequest::UserAgentHeader; executed: return QNetworkRequest::UserAgentHeader;Execution Count:8 | 8 |
| 784 | break; | 0 |
| 785 | } | - |
| 786 | | - |
| 787 | return QNetworkRequest::KnownHeaders(-1); // nothing found executed: return QNetworkRequest::KnownHeaders(-1);Execution Count:2719 | 2719 |
| 788 | } | - |
| 789 | | - |
| 790 | static QVariant parseHttpDate(const QByteArray &raw) | - |
| 791 | { | - |
| 792 | QDateTime dt = QNetworkHeadersPrivate::fromHttpDate(raw); executed (the execution status of this line is deduced): QDateTime dt = QNetworkHeadersPrivate::fromHttpDate(raw); | - |
| 793 | if (dt.isValid()) partially evaluated: dt.isValid()| yes Evaluation Count:277 | no Evaluation Count:0 |
| 0-277 |
| 794 | return dt; executed: return dt;Execution Count:277 | 277 |
| 795 | return QVariant(); // transform an invalid QDateTime into a null QVariant never executed: return QVariant(); | 0 |
| 796 | } | - |
| 797 | | - |
| 798 | static QVariant parseCookieHeader(const QByteArray &raw) | - |
| 799 | { | - |
| 800 | QList<QNetworkCookie> result; executed (the execution status of this line is deduced): QList<QNetworkCookie> result; | - |
| 801 | QList<QByteArray> cookieList = raw.split(';'); executed (the execution status of this line is deduced): QList<QByteArray> cookieList = raw.split(';'); | - |
| 802 | foreach (const QByteArray &cookie, cookieList) { executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(cookieList)> _container_(cookieList); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QByteArray &cookie = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
| 803 | QList<QNetworkCookie> parsed = QNetworkCookie::parseCookies(cookie.trimmed()); executed (the execution status of this line is deduced): QList<QNetworkCookie> parsed = QNetworkCookie::parseCookies(cookie.trimmed()); | - |
| 804 | if (parsed.count() != 1) partially evaluated: parsed.count() != 1| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
| 805 | return QVariant(); // invalid Cookie: header never executed: return QVariant(); | 0 |
| 806 | | - |
| 807 | result += parsed; executed (the execution status of this line is deduced): result += parsed; | - |
| 808 | } executed: }Execution Count:3 | 3 |
| 809 | | - |
| 810 | return QVariant::fromValue(result); executed: return QVariant::fromValue(result);Execution Count:2 | 2 |
| 811 | } | - |
| 812 | | - |
| 813 | static QVariant parseHeaderValue(QNetworkRequest::KnownHeaders header, const QByteArray &value) | - |
| 814 | { | - |
| 815 | // header is always a valid value | - |
| 816 | switch (header) { | - |
| 817 | case QNetworkRequest::UserAgentHeader: | - |
| 818 | case QNetworkRequest::ServerHeader: | - |
| 819 | case QNetworkRequest::ContentTypeHeader: | - |
| 820 | // copy exactly, convert to QString | - |
| 821 | return QString::fromLatin1(value); executed: return QString::fromLatin1(value);Execution Count:1460 | 1460 |
| 822 | | - |
| 823 | case QNetworkRequest::ContentLengthHeader: { | - |
| 824 | bool ok; executed (the execution status of this line is deduced): bool ok; | - |
| 825 | qint64 result = value.trimmed().toLongLong(&ok); executed (the execution status of this line is deduced): qint64 result = value.trimmed().toLongLong(&ok); | - |
| 826 | if (ok) evaluated: ok| yes Evaluation Count:518 | yes Evaluation Count:2 |
| 2-518 |
| 827 | return result; executed: return result;Execution Count:518 | 518 |
| 828 | return QVariant(); executed: return QVariant();Execution Count:2 | 2 |
| 829 | } | - |
| 830 | | - |
| 831 | case QNetworkRequest::LocationHeader: { | - |
| 832 | QUrl result = QUrl::fromEncoded(value, QUrl::StrictMode); executed (the execution status of this line is deduced): QUrl result = QUrl::fromEncoded(value, QUrl::StrictMode); | - |
| 833 | if (result.isValid() && !result.scheme().isEmpty()) evaluated: result.isValid()| yes Evaluation Count:36 | yes Evaluation Count:2 |
evaluated: !result.scheme().isEmpty()| yes Evaluation Count:35 | yes Evaluation Count:1 |
| 1-36 |
| 834 | return result; executed: return result;Execution Count:35 | 35 |
| 835 | return QVariant(); executed: return QVariant();Execution Count:3 | 3 |
| 836 | } | - |
| 837 | | - |
| 838 | case QNetworkRequest::LastModifiedHeader: | - |
| 839 | return parseHttpDate(value); executed: return parseHttpDate(value);Execution Count:277 | 277 |
| 840 | | - |
| 841 | case QNetworkRequest::CookieHeader: | - |
| 842 | return parseCookieHeader(value); executed: return parseCookieHeader(value);Execution Count:2 | 2 |
| 843 | | - |
| 844 | case QNetworkRequest::SetCookieHeader: | - |
| 845 | return QVariant::fromValue(QNetworkCookie::parseCookies(value)); executed: return QVariant::fromValue(QNetworkCookie::parseCookies(value));Execution Count:17 | 17 |
| 846 | | - |
| 847 | default: | - |
| 848 | Q_ASSERT(0); never executed (the execution status of this line is deduced): qt_noop(); | - |
| 849 | } | 0 |
| 850 | return QVariant(); never executed: return QVariant(); | 0 |
| 851 | } | - |
| 852 | | - |
| 853 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator | - |
| 854 | QNetworkHeadersPrivate::findRawHeader(const QByteArray &key) const | - |
| 855 | { | - |
| 856 | RawHeadersList::ConstIterator it = rawHeaders.constBegin(); executed (the execution status of this line is deduced): RawHeadersList::ConstIterator it = rawHeaders.constBegin(); | - |
| 857 | RawHeadersList::ConstIterator end = rawHeaders.constEnd(); executed (the execution status of this line is deduced): RawHeadersList::ConstIterator end = rawHeaders.constEnd(); | - |
| 858 | for ( ; it != end; ++it) evaluated: it != end| yes Evaluation Count:17836 | yes Evaluation Count:5297 |
| 5297-17836 |
| 859 | if (qstricmp(it->first.constData(), key.constData()) == 0) evaluated: qstricmp(it->first.constData(), key.constData()) == 0| yes Evaluation Count:985 | yes Evaluation Count:16851 |
| 985-16851 |
| 860 | return it; executed: return it;Execution Count:985 | 985 |
| 861 | | - |
| 862 | return end; // not found executed: return end;Execution Count:5297 | 5297 |
| 863 | } | - |
| 864 | | - |
| 865 | QNetworkHeadersPrivate::RawHeadersList QNetworkHeadersPrivate::allRawHeaders() const | - |
| 866 | { | - |
| 867 | return rawHeaders; executed: return rawHeaders;Execution Count:20 | 20 |
| 868 | } | - |
| 869 | | - |
| 870 | QList<QByteArray> QNetworkHeadersPrivate::rawHeadersKeys() const | - |
| 871 | { | - |
| 872 | QList<QByteArray> result; executed (the execution status of this line is deduced): QList<QByteArray> result; | - |
| 873 | RawHeadersList::ConstIterator it = rawHeaders.constBegin(), executed (the execution status of this line is deduced): RawHeadersList::ConstIterator it = rawHeaders.constBegin(), | - |
| 874 | end = rawHeaders.constEnd(); executed (the execution status of this line is deduced): end = rawHeaders.constEnd(); | - |
| 875 | for ( ; it != end; ++it) evaluated: it != end| yes Evaluation Count:1057 | yes Evaluation Count:852 |
| 852-1057 |
| 876 | result << it->first; executed: result << it->first;Execution Count:1057 | 1057 |
| 877 | | - |
| 878 | return result; executed: return result;Execution Count:852 | 852 |
| 879 | } | - |
| 880 | | - |
| 881 | void QNetworkHeadersPrivate::setRawHeader(const QByteArray &key, const QByteArray &value) | - |
| 882 | { | - |
| 883 | if (key.isEmpty()) evaluated: key.isEmpty()| yes Evaluation Count:2 | yes Evaluation Count:4863 |
| 2-4863 |
| 884 | // refuse to accept an empty raw header | - |
| 885 | return; executed: return;Execution Count:2 | 2 |
| 886 | | - |
| 887 | setRawHeaderInternal(key, value); executed (the execution status of this line is deduced): setRawHeaderInternal(key, value); | - |
| 888 | parseAndSetHeader(key, value); executed (the execution status of this line is deduced): parseAndSetHeader(key, value); | - |
| 889 | } executed: }Execution Count:4863 | 4863 |
| 890 | | - |
| 891 | /*! | - |
| 892 | \internal | - |
| 893 | Sets the internal raw headers list to match \a list. The cooked headers | - |
| 894 | will also be updated. | - |
| 895 | | - |
| 896 | If \a list contains duplicates, they will be stored, but only the first one | - |
| 897 | is usually accessed. | - |
| 898 | */ | - |
| 899 | void QNetworkHeadersPrivate::setAllRawHeaders(const RawHeadersList &list) | - |
| 900 | { | - |
| 901 | cookedHeaders.clear(); executed (the execution status of this line is deduced): cookedHeaders.clear(); | - |
| 902 | rawHeaders = list; executed (the execution status of this line is deduced): rawHeaders = list; | - |
| 903 | | - |
| 904 | RawHeadersList::ConstIterator it = rawHeaders.constBegin(); executed (the execution status of this line is deduced): RawHeadersList::ConstIterator it = rawHeaders.constBegin(); | - |
| 905 | RawHeadersList::ConstIterator end = rawHeaders.constEnd(); executed (the execution status of this line is deduced): RawHeadersList::ConstIterator end = rawHeaders.constEnd(); | - |
| 906 | for ( ; it != end; ++it) evaluated: it != end| yes Evaluation Count:171 | yes Evaluation Count:109 |
| 109-171 |
| 907 | parseAndSetHeader(it->first, it->second); executed: parseAndSetHeader(it->first, it->second);Execution Count:171 | 171 |
| 908 | } executed: }Execution Count:109 | 109 |
| 909 | | - |
| 910 | void QNetworkHeadersPrivate::setCookedHeader(QNetworkRequest::KnownHeaders header, | - |
| 911 | const QVariant &value) | - |
| 912 | { | - |
| 913 | QByteArray name = headerName(header); executed (the execution status of this line is deduced): QByteArray name = headerName(header); | - |
| 914 | if (name.isEmpty()) { partially evaluated: name.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:398 |
| 0-398 |
| 915 | // headerName verifies that \a header is a known value | - |
| 916 | qWarning("QNetworkRequest::setHeader: invalid header value KnownHeader(%d) received", header); never executed (the execution status of this line is deduced): QMessageLogger("access/qnetworkrequest.cpp", 916, __PRETTY_FUNCTION__).warning("QNetworkRequest::setHeader: invalid header value KnownHeader(%d) received", header); | - |
| 917 | return; | 0 |
| 918 | } | - |
| 919 | | - |
| 920 | if (value.isNull()) { evaluated: value.isNull()| yes Evaluation Count:3 | yes Evaluation Count:395 |
| 3-395 |
| 921 | setRawHeaderInternal(name, QByteArray()); executed (the execution status of this line is deduced): setRawHeaderInternal(name, QByteArray()); | - |
| 922 | cookedHeaders.remove(header); executed (the execution status of this line is deduced): cookedHeaders.remove(header); | - |
| 923 | } else { executed: }Execution Count:3 | 3 |
| 924 | QByteArray rawValue = headerValue(header, value); executed (the execution status of this line is deduced): QByteArray rawValue = headerValue(header, value); | - |
| 925 | if (rawValue.isEmpty()) { partially evaluated: rawValue.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:395 |
| 0-395 |
| 926 | qWarning("QNetworkRequest::setHeader: QVariant of type %s cannot be used with header %s", never executed (the execution status of this line is deduced): QMessageLogger("access/qnetworkrequest.cpp", 926, __PRETTY_FUNCTION__).warning("QNetworkRequest::setHeader: QVariant of type %s cannot be used with header %s", | - |
| 927 | value.typeName(), name.constData()); never executed (the execution status of this line is deduced): value.typeName(), name.constData()); | - |
| 928 | return; | 0 |
| 929 | } | - |
| 930 | | - |
| 931 | setRawHeaderInternal(name, rawValue); executed (the execution status of this line is deduced): setRawHeaderInternal(name, rawValue); | - |
| 932 | cookedHeaders.insert(header, value); executed (the execution status of this line is deduced): cookedHeaders.insert(header, value); | - |
| 933 | } executed: }Execution Count:395 | 395 |
| 934 | } | - |
| 935 | | - |
| 936 | void QNetworkHeadersPrivate::setRawHeaderInternal(const QByteArray &key, const QByteArray &value) | - |
| 937 | { | - |
| 938 | RawHeadersList::Iterator it = rawHeaders.begin(); executed (the execution status of this line is deduced): RawHeadersList::Iterator it = rawHeaders.begin(); | - |
| 939 | while (it != rawHeaders.end()) { evaluated: it != rawHeaders.end()| yes Evaluation Count:15480 | yes Evaluation Count:5261 |
| 5261-15480 |
| 940 | if (qstricmp(it->first.constData(), key.constData()) == 0) evaluated: qstricmp(it->first.constData(), key.constData()) == 0| yes Evaluation Count:47 | yes Evaluation Count:15433 |
| 47-15433 |
| 941 | it = rawHeaders.erase(it); executed: it = rawHeaders.erase(it);Execution Count:47 | 47 |
| 942 | else | - |
| 943 | ++it; executed: ++it;Execution Count:15433 | 15433 |
| 944 | } | - |
| 945 | | - |
| 946 | if (value.isNull()) evaluated: value.isNull()| yes Evaluation Count:9 | yes Evaluation Count:5252 |
| 9-5252 |
| 947 | return; // only wanted to erase key executed: return;Execution Count:9 | 9 |
| 948 | | - |
| 949 | RawHeaderPair pair; executed (the execution status of this line is deduced): RawHeaderPair pair; | - |
| 950 | pair.first = key; executed (the execution status of this line is deduced): pair.first = key; | - |
| 951 | pair.second = value; executed (the execution status of this line is deduced): pair.second = value; | - |
| 952 | rawHeaders.append(pair); executed (the execution status of this line is deduced): rawHeaders.append(pair); | - |
| 953 | } executed: }Execution Count:5252 | 5252 |
| 954 | | - |
| 955 | void QNetworkHeadersPrivate::parseAndSetHeader(const QByteArray &key, const QByteArray &value) | - |
| 956 | { | - |
| 957 | // is it a known header? | - |
| 958 | QNetworkRequest::KnownHeaders parsedKey = parseHeaderName(key); executed (the execution status of this line is deduced): QNetworkRequest::KnownHeaders parsedKey = parseHeaderName(key); | - |
| 959 | if (parsedKey != QNetworkRequest::KnownHeaders(-1)) { evaluated: parsedKey != QNetworkRequest::KnownHeaders(-1)| yes Evaluation Count:2315 | yes Evaluation Count:2719 |
| 2315-2719 |
| 960 | if (value.isNull()) { partially evaluated: value.isNull()| no Evaluation Count:0 | yes Evaluation Count:2315 |
| 0-2315 |
| 961 | cookedHeaders.remove(parsedKey); never executed (the execution status of this line is deduced): cookedHeaders.remove(parsedKey); | - |
| 962 | } else if (parsedKey == QNetworkRequest::ContentLengthHeader never executed: } evaluated: parsedKey == QNetworkRequest::ContentLengthHeader| yes Evaluation Count:521 | yes Evaluation Count:1794 |
| 0-1794 |
| 963 | && cookedHeaders.contains(QNetworkRequest::ContentLengthHeader)) { evaluated: cookedHeaders.contains(QNetworkRequest::ContentLengthHeader)| yes Evaluation Count:1 | yes Evaluation Count:520 |
| 1-520 |
| 964 | // Only set the cooked header "Content-Length" once. | - |
| 965 | // See bug QTBUG-15311 | - |
| 966 | } else { executed: }Execution Count:1 | 1 |
| 967 | cookedHeaders.insert(parsedKey, parseHeaderValue(parsedKey, value)); executed (the execution status of this line is deduced): cookedHeaders.insert(parsedKey, parseHeaderValue(parsedKey, value)); | - |
| 968 | } executed: }Execution Count:2314 | 2314 |
| 969 | | - |
| 970 | } | - |
| 971 | } executed: }Execution Count:5034 | 5034 |
| 972 | | - |
| 973 | // Fast month string to int conversion. This code | - |
| 974 | // assumes that the Month name is correct and that | - |
| 975 | // the string is at least three chars long. | - |
| 976 | static int name_to_month(const char* month_str) | - |
| 977 | { | - |
| 978 | switch (month_str[0]) { | - |
| 979 | case 'J': | - |
| 980 | switch (month_str[1]) { | - |
| 981 | case 'a': | - |
| 982 | return 1; executed: return 1;Execution Count:24 | 24 |
| 983 | case 'u': | - |
| 984 | switch (month_str[2] ) { | - |
| 985 | case 'n': | - |
| 986 | return 6; executed: return 6;Execution Count:18 | 18 |
| 987 | case 'l': | - |
| 988 | return 7; never executed: return 7; | 0 |
| 989 | } | - |
| 990 | } | 0 |
| 991 | break; | 0 |
| 992 | case 'F': | - |
| 993 | return 2; never executed: return 2; | 0 |
| 994 | case 'M': | - |
| 995 | switch (month_str[2] ) { | - |
| 996 | case 'r': | - |
| 997 | return 3; executed: return 3;Execution Count:1 | 1 |
| 998 | case 'y': | - |
| 999 | return 5; executed: return 5;Execution Count:61 | 61 |
| 1000 | } | - |
| 1001 | break; | 0 |
| 1002 | case 'A': | - |
| 1003 | switch (month_str[1]) { | - |
| 1004 | case 'p': | - |
| 1005 | return 4; never executed: return 4; | 0 |
| 1006 | case 'u': | - |
| 1007 | return 8; never executed: return 8; | 0 |
| 1008 | } | - |
| 1009 | break; | 0 |
| 1010 | case 'O': | - |
| 1011 | return 10; executed: return 10;Execution Count:215 | 215 |
| 1012 | case 'S': | - |
| 1013 | return 9; never executed: return 9; | 0 |
| 1014 | case 'N': | - |
| 1015 | return 11; executed: return 11;Execution Count:14 | 14 |
| 1016 | case 'D': | - |
| 1017 | return 12; never executed: return 12; | 0 |
| 1018 | } | - |
| 1019 | | - |
| 1020 | return 0; never executed: return 0; | 0 |
| 1021 | } | - |
| 1022 | | - |
| 1023 | QDateTime QNetworkHeadersPrivate::fromHttpDate(const QByteArray &value) | - |
| 1024 | { | - |
| 1025 | // HTTP dates have three possible formats: | - |
| 1026 | // RFC 1123/822 - ddd, dd MMM yyyy hh:mm:ss "GMT" | - |
| 1027 | // RFC 850 - dddd, dd-MMM-yy hh:mm:ss "GMT" | - |
| 1028 | // ANSI C's asctime - ddd MMM d hh:mm:ss yyyy | - |
| 1029 | // We only handle them exactly. If they deviate, we bail out. | - |
| 1030 | | - |
| 1031 | int pos = value.indexOf(','); executed (the execution status of this line is deduced): int pos = value.indexOf(','); | - |
| 1032 | QDateTime dt; executed (the execution status of this line is deduced): QDateTime dt; | - |
| 1033 | #ifndef QT_NO_DATESTRING | - |
| 1034 | if (pos == -1) { evaluated: pos == -1| yes Evaluation Count:1 | yes Evaluation Count:334 |
| 1-334 |
| 1035 | // no comma -> asctime(3) format | - |
| 1036 | dt = QDateTime::fromString(QString::fromLatin1(value), Qt::TextDate); executed (the execution status of this line is deduced): dt = QDateTime::fromString(QString::fromLatin1(value), Qt::TextDate); | - |
| 1037 | } else { executed: }Execution Count:1 | 1 |
| 1038 | // Use sscanf over QLocal/QDateTimeParser for speed reasons. See the | - |
| 1039 | // Qt WebKit performance benchmarks to get an idea. | - |
| 1040 | if (pos == 3) { evaluated: pos == 3| yes Evaluation Count:333 | yes Evaluation Count:1 |
| 1-333 |
| 1041 | char month_name[4]; executed (the execution status of this line is deduced): char month_name[4]; | - |
| 1042 | int day, year, hour, minute, second; executed (the execution status of this line is deduced): int day, year, hour, minute, second; | - |
| 1043 | #ifdef Q_CC_MSVC | - |
| 1044 | // Use secure version to avoid compiler warning | - |
| 1045 | if (sscanf_s(value.constData(), "%*3s, %d %3s %d %d:%d:%d 'GMT'", &day, month_name, 4, &year, &hour, &minute, &second) == 6) | - |
| 1046 | #else | - |
| 1047 | // The POSIX secure mode is %ms (which allocates memory), too bleeding edge for now | - |
| 1048 | // In any case this is already safe as field width is specified. | - |
| 1049 | if (sscanf(value.constData(), "%*3s, %d %3s %d %d:%d:%d 'GMT'", &day, month_name, &year, &hour, &minute, &second) == 6) partially evaluated: sscanf(value.constData(), "%*3s, %d %3s %d %d:%d:%d 'GMT'", &day, month_name, &year, &hour, &minute, &second) == 6| yes Evaluation Count:333 | no Evaluation Count:0 |
| 0-333 |
| 1050 | #endif | - |
| 1051 | dt = QDateTime(QDate(year, name_to_month(month_name), day), QTime(hour, minute, second)); executed: dt = QDateTime(QDate(year, name_to_month(month_name), day), QTime(hour, minute, second));Execution Count:333 | 333 |
| 1052 | } else { executed: }Execution Count:333 | 333 |
| 1053 | QLocale c = QLocale::c(); executed (the execution status of this line is deduced): QLocale c = QLocale::c(); | - |
| 1054 | // eat the weekday, the comma and the space following it | - |
| 1055 | QString sansWeekday = QString::fromLatin1(value.constData() + pos + 2); executed (the execution status of this line is deduced): QString sansWeekday = QString::fromLatin1(value.constData() + pos + 2); | - |
| 1056 | // must be RFC 850 date | - |
| 1057 | dt = c.toDateTime(sansWeekday, QLatin1String("dd-MMM-yy hh:mm:ss 'GMT'")); executed (the execution status of this line is deduced): dt = c.toDateTime(sansWeekday, QLatin1String("dd-MMM-yy hh:mm:ss 'GMT'")); | - |
| 1058 | } executed: }Execution Count:1 | 1 |
| 1059 | } | - |
| 1060 | #endif // QT_NO_DATESTRING | - |
| 1061 | | - |
| 1062 | if (dt.isValid()) partially evaluated: dt.isValid()| yes Evaluation Count:335 | no Evaluation Count:0 |
| 0-335 |
| 1063 | dt.setTimeSpec(Qt::UTC); executed: dt.setTimeSpec(Qt::UTC);Execution Count:335 | 335 |
| 1064 | return dt; executed: return dt;Execution Count:335 | 335 |
| 1065 | } | - |
| 1066 | | - |
| 1067 | QByteArray QNetworkHeadersPrivate::toHttpDate(const QDateTime &dt) | - |
| 1068 | { | - |
| 1069 | return QLocale::c().toString(dt, QLatin1String("ddd, dd MMM yyyy hh:mm:ss 'GMT'")) executed: return QLocale::c().toString(dt, QLatin1String("ddd, dd MMM yyyy hh:mm:ss 'GMT'")) .toLatin1();Execution Count:70 | 70 |
| 1070 | .toLatin1(); executed: return QLocale::c().toString(dt, QLatin1String("ddd, dd MMM yyyy hh:mm:ss 'GMT'")) .toLatin1();Execution Count:70 | 70 |
| 1071 | } | - |
| 1072 | | - |
| 1073 | QT_END_NAMESPACE | - |
| 1074 | | - |
| | |