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