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