access/qhttpnetworkrequest.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtNetwork module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qhttpnetworkrequest_p.h" -
43#include "private/qnoncontiguousbytedevice_p.h" -
44 -
45#ifndef QT_NO_HTTP -
46 -
47QT_BEGIN_NAMESPACE -
48 -
49QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op, -
50 QHttpNetworkRequest::Priority pri, const QUrl &newUrl) -
51 : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(0), -
52 autoDecompress(false), pipeliningAllowed(false), withCredentials(true) -
53{ -
54}
executed: }
Execution Count:5837
5837
55 -
56QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(const QHttpNetworkRequestPrivate &other) -
57 : QHttpNetworkHeaderPrivate(other) -
58{ -
59 operation = other.operation;
executed (the execution status of this line is deduced): operation = other.operation;
-
60 priority = other.priority;
executed (the execution status of this line is deduced): priority = other.priority;
-
61 uploadByteDevice = other.uploadByteDevice;
executed (the execution status of this line is deduced): uploadByteDevice = other.uploadByteDevice;
-
62 autoDecompress = other.autoDecompress;
executed (the execution status of this line is deduced): autoDecompress = other.autoDecompress;
-
63 pipeliningAllowed = other.pipeliningAllowed;
executed (the execution status of this line is deduced): pipeliningAllowed = other.pipeliningAllowed;
-
64 customVerb = other.customVerb;
executed (the execution status of this line is deduced): customVerb = other.customVerb;
-
65 withCredentials = other.withCredentials;
executed (the execution status of this line is deduced): withCredentials = other.withCredentials;
-
66 ssl = other.ssl;
executed (the execution status of this line is deduced): ssl = other.ssl;
-
67}
executed: }
Execution Count:867
867
68 -
69QHttpNetworkRequestPrivate::~QHttpNetworkRequestPrivate() -
70{ -
71} -
72 -
73bool QHttpNetworkRequestPrivate::operator==(const QHttpNetworkRequestPrivate &other) const -
74{ -
75 return QHttpNetworkHeaderPrivate::operator==(other)
never executed: return QHttpNetworkHeaderPrivate::operator==(other) && (operation == other.operation) && (ssl == other.ssl) && (uploadByteDevice == other.uploadByteDevice);
0
76 && (operation == other.operation)
never executed: return QHttpNetworkHeaderPrivate::operator==(other) && (operation == other.operation) && (ssl == other.ssl) && (uploadByteDevice == other.uploadByteDevice);
0
77 && (ssl == other.ssl)
never executed: return QHttpNetworkHeaderPrivate::operator==(other) && (operation == other.operation) && (ssl == other.ssl) && (uploadByteDevice == other.uploadByteDevice);
0
78 && (uploadByteDevice == other.uploadByteDevice);
never executed: return QHttpNetworkHeaderPrivate::operator==(other) && (operation == other.operation) && (ssl == other.ssl) && (uploadByteDevice == other.uploadByteDevice);
0
79} -
80 -
81QByteArray QHttpNetworkRequestPrivate::methodName() const -
82{ -
83 switch (operation) { -
84 case QHttpNetworkRequest::Get: -
85 return "GET";
executed: return "GET";
Execution Count:707
707
86 case QHttpNetworkRequest::Head: -
87 return "HEAD";
executed: return "HEAD";
Execution Count:47
47
88 case QHttpNetworkRequest::Post: -
89 return "POST";
executed: return "POST";
Execution Count:238
238
90 case QHttpNetworkRequest::Options: -
91 return "OPTIONS";
never executed: return "OPTIONS";
0
92 case QHttpNetworkRequest::Put: -
93 return "PUT";
executed: return "PUT";
Execution Count:36
36
94 case QHttpNetworkRequest::Delete: -
95 return "DELETE";
executed: return "DELETE";
Execution Count:7
7
96 case QHttpNetworkRequest::Trace: -
97 return "TRACE";
never executed: return "TRACE";
0
98 case QHttpNetworkRequest::Connect: -
99 return "CONNECT";
never executed: return "CONNECT";
0
100 case QHttpNetworkRequest::Custom: -
101 return customVerb;
executed: return customVerb;
Execution Count:6
6
102 default: -
103 break;
never executed: break;
0
104 } -
105 return QByteArray();
never executed: return QByteArray();
0
106} -
107 -
108QByteArray QHttpNetworkRequestPrivate::uri(bool throughProxy) const -
109{ -
110 QUrl::FormattingOptions format(QUrl::RemoveFragment | QUrl::RemoveUserInfo | QUrl::FullyEncoded);
executed (the execution status of this line is deduced): QUrl::FormattingOptions format(QUrl::RemoveFragment | QUrl::RemoveUserInfo | QUrl::FullyEncoded);
-
111 -
112 // for POST, query data is send as content -
113 if (operation == QHttpNetworkRequest::Post && !uploadByteDevice)
evaluated: operation == QHttpNetworkRequest::Post
TRUEFALSE
yes
Evaluation Count:238
yes
Evaluation Count:803
partially evaluated: !uploadByteDevice
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:238
0-803
114 format |= QUrl::RemoveQuery;
never executed: format |= QUrl::RemoveQuery;
0
115 // for requests through proxy, the Request-URI contains full url -
116 if (!throughProxy)
evaluated: !throughProxy
TRUEFALSE
yes
Evaluation Count:937
yes
Evaluation Count:104
104-937
117 format |= QUrl::RemoveScheme | QUrl::RemoveAuthority;
executed: format |= QUrl::RemoveScheme | QUrl::RemoveAuthority;
Execution Count:937
937
118 QUrl copy = url;
executed (the execution status of this line is deduced): QUrl copy = url;
-
119 if (copy.path().isEmpty())
evaluated: copy.path().isEmpty()
TRUEFALSE
yes
Evaluation Count:179
yes
Evaluation Count:862
179-862
120 copy.setPath(QStringLiteral("/"));
executed: copy.setPath(QString::fromUtf8("" "/" "", sizeof("/") - 1));
Execution Count:179
179
121 QByteArray uri = copy.toEncoded(format);
executed (the execution status of this line is deduced): QByteArray uri = copy.toEncoded(format);
-
122 return uri;
executed: return uri;
Execution Count:1041
1041
123} -
124 -
125QByteArray QHttpNetworkRequestPrivate::header(const QHttpNetworkRequest &request, bool throughProxy) -
126{ -
127 QList<QPair<QByteArray, QByteArray> > fields = request.header();
executed (the execution status of this line is deduced): QList<QPair<QByteArray, QByteArray> > fields = request.header();
-
128 QByteArray ba;
executed (the execution status of this line is deduced): QByteArray ba;
-
129 ba.reserve(40 + fields.length()*25); // very rough lower bound estimation
executed (the execution status of this line is deduced): ba.reserve(40 + fields.length()*25);
-
130 -
131 ba += request.d->methodName();
executed (the execution status of this line is deduced): ba += request.d->methodName();
-
132 ba += ' ';
executed (the execution status of this line is deduced): ba += ' ';
-
133 ba += request.d->uri(throughProxy);
executed (the execution status of this line is deduced): ba += request.d->uri(throughProxy);
-
134 -
135 ba += " HTTP/";
executed (the execution status of this line is deduced): ba += " HTTP/";
-
136 ba += QByteArray::number(request.majorVersion());
executed (the execution status of this line is deduced): ba += QByteArray::number(request.majorVersion());
-
137 ba += '.';
executed (the execution status of this line is deduced): ba += '.';
-
138 ba += QByteArray::number(request.minorVersion());
executed (the execution status of this line is deduced): ba += QByteArray::number(request.minorVersion());
-
139 ba += "\r\n";
executed (the execution status of this line is deduced): ba += "\r\n";
-
140 -
141 QList<QPair<QByteArray, QByteArray> >::const_iterator it = fields.constBegin();
executed (the execution status of this line is deduced): QList<QPair<QByteArray, QByteArray> >::const_iterator it = fields.constBegin();
-
142 QList<QPair<QByteArray, QByteArray> >::const_iterator endIt = fields.constEnd();
executed (the execution status of this line is deduced): QList<QPair<QByteArray, QByteArray> >::const_iterator endIt = fields.constEnd();
-
143 for (; it != endIt; ++it) {
evaluated: it != endIt
TRUEFALSE
yes
Evaluation Count:4974
yes
Evaluation Count:859
859-4974
144 ba += it->first;
executed (the execution status of this line is deduced): ba += it->first;
-
145 ba += ": ";
executed (the execution status of this line is deduced): ba += ": ";
-
146 ba += it->second;
executed (the execution status of this line is deduced): ba += it->second;
-
147 ba += "\r\n";
executed (the execution status of this line is deduced): ba += "\r\n";
-
148 }
executed: }
Execution Count:4974
4974
149 if (request.d->operation == QHttpNetworkRequest::Post) {
evaluated: request.d->operation == QHttpNetworkRequest::Post
TRUEFALSE
yes
Evaluation Count:187
yes
Evaluation Count:672
187-672
150 // add content type, if not set in the request -
151 if (request.headerField("content-type").isEmpty()) {
partially evaluated: request.headerField("content-type").isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:187
0-187
152 //Content-Type is mandatory. We can't say anything about the encoding, but x-www-form-urlencoded is the most likely to work. -
153 //This warning indicates a bug in application code not setting a required header. -
154 //Note that if using QHttpMultipart, the content-type is set in QNetworkAccessManagerPrivate::prepareMultipart already -
155 qWarning("content-type missing in HTTP POST, defaulting to application/x-www-form-urlencoded. Use QNetworkRequest::setHeader() to fix this problem.");
never executed (the execution status of this line is deduced): QMessageLogger("access/qhttpnetworkrequest.cpp", 155, __PRETTY_FUNCTION__).warning("content-type missing in HTTP POST, defaulting to application/x-www-form-urlencoded. Use QNetworkRequest::setHeader() to fix this problem.");
-
156 ba += "Content-Type: application/x-www-form-urlencoded\r\n";
never executed (the execution status of this line is deduced): ba += "Content-Type: application/x-www-form-urlencoded\r\n";
-
157 }
never executed: }
0
158 if (!request.d->uploadByteDevice && request.d->url.hasQuery()) {
partially evaluated: !request.d->uploadByteDevice
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:187
never evaluated: request.d->url.hasQuery()
0-187
159 QByteArray query = request.d->url.query(QUrl::FullyEncoded).toLatin1();
never executed (the execution status of this line is deduced): QByteArray query = request.d->url.query(QUrl::FullyEncoded).toLatin1();
-
160 ba += "Content-Length: ";
never executed (the execution status of this line is deduced): ba += "Content-Length: ";
-
161 ba += QByteArray::number(query.size());
never executed (the execution status of this line is deduced): ba += QByteArray::number(query.size());
-
162 ba += "\r\n\r\n";
never executed (the execution status of this line is deduced): ba += "\r\n\r\n";
-
163 ba += query;
never executed (the execution status of this line is deduced): ba += query;
-
164 } else {
never executed: }
0
165 ba += "\r\n";
executed (the execution status of this line is deduced): ba += "\r\n";
-
166 }
executed: }
Execution Count:187
187
167 } else { -
168 ba += "\r\n";
executed (the execution status of this line is deduced): ba += "\r\n";
-
169 }
executed: }
Execution Count:672
672
170 return ba;
executed: return ba;
Execution Count:859
859
171} -
172 -
173 -
174// QHttpNetworkRequest -
175 -
176QHttpNetworkRequest::QHttpNetworkRequest(const QUrl &url, Operation operation, Priority priority) -
177 : d(new QHttpNetworkRequestPrivate(operation, priority, url)) -
178{ -
179}
executed: }
Execution Count:5837
5837
180 -
181QHttpNetworkRequest::QHttpNetworkRequest(const QHttpNetworkRequest &other) -
182 : QHttpNetworkHeader(other), d(other.d) -
183{ -
184}
executed: }
Execution Count:3739
3739
185 -
186QHttpNetworkRequest::~QHttpNetworkRequest() -
187{ -
188} -
189 -
190QUrl QHttpNetworkRequest::url() const -
191{ -
192 return d->url;
executed: return d->url;
Execution Count:3179
3179
193} -
194void QHttpNetworkRequest::setUrl(const QUrl &url) -
195{ -
196 d->url = url;
executed (the execution status of this line is deduced): d->url = url;
-
197}
executed: }
Execution Count:738
738
198 -
199bool QHttpNetworkRequest::isSsl() const -
200{ -
201 return d->ssl;
executed: return d->ssl;
Execution Count:694
694
202} -
203void QHttpNetworkRequest::setSsl(bool s) -
204{ -
205 d->ssl = s;
executed (the execution status of this line is deduced): d->ssl = s;
-
206}
executed: }
Execution Count:712
712
207 -
208qint64 QHttpNetworkRequest::contentLength() const -
209{ -
210 return d->contentLength();
executed: return d->contentLength();
Execution Count:584
584
211} -
212 -
213void QHttpNetworkRequest::setContentLength(qint64 length) -
214{ -
215 d->setContentLength(length);
executed (the execution status of this line is deduced): d->setContentLength(length);
-
216}
executed: }
Execution Count:178
178
217 -
218QList<QPair<QByteArray, QByteArray> > QHttpNetworkRequest::header() const -
219{ -
220 return d->fields;
executed: return d->fields;
Execution Count:859
859
221} -
222 -
223QByteArray QHttpNetworkRequest::headerField(const QByteArray &name, const QByteArray &defaultValue) const -
224{ -
225 return d->headerField(name, defaultValue);
executed: return d->headerField(name, defaultValue);
Execution Count:3648
3648
226} -
227 -
228void QHttpNetworkRequest::setHeaderField(const QByteArray &name, const QByteArray &data) -
229{ -
230 d->setHeaderField(name, data);
executed (the execution status of this line is deduced): d->setHeaderField(name, data);
-
231}
executed: }
Execution Count:3966
3966
232 -
233QHttpNetworkRequest &QHttpNetworkRequest::operator=(const QHttpNetworkRequest &other) -
234{ -
235 d = other.d;
executed (the execution status of this line is deduced): d = other.d;
-
236 return *this;
executed: return *this;
Execution Count:2743
2743
237} -
238 -
239bool QHttpNetworkRequest::operator==(const QHttpNetworkRequest &other) const -
240{ -
241 return d->operator==(*other.d);
never executed: return d->operator==(*other.d);
0
242} -
243 -
244QHttpNetworkRequest::Operation QHttpNetworkRequest::operation() const -
245{ -
246 return d->operation;
executed: return d->operation;
Execution Count:872
872
247} -
248 -
249void QHttpNetworkRequest::setOperation(Operation operation) -
250{ -
251 d->operation = operation;
executed (the execution status of this line is deduced): d->operation = operation;
-
252}
executed: }
Execution Count:709
709
253 -
254QByteArray QHttpNetworkRequest::customVerb() const -
255{ -
256 return d->customVerb;
never executed: return d->customVerb;
0
257} -
258 -
259void QHttpNetworkRequest::setCustomVerb(const QByteArray &customVerb) -
260{ -
261 d->customVerb = customVerb;
executed (the execution status of this line is deduced): d->customVerb = customVerb;
-
262}
executed: }
Execution Count:6
6
263 -
264QHttpNetworkRequest::Priority QHttpNetworkRequest::priority() const -
265{ -
266 return d->priority;
executed: return d->priority;
Execution Count:694
694
267} -
268 -
269void QHttpNetworkRequest::setPriority(Priority priority) -
270{ -
271 d->priority = priority;
executed (the execution status of this line is deduced): d->priority = priority;
-
272}
executed: }
Execution Count:709
709
273 -
274bool QHttpNetworkRequest::isPipeliningAllowed() const -
275{ -
276 return d->pipeliningAllowed;
executed: return d->pipeliningAllowed;
Execution Count:805
805
277} -
278 -
279void QHttpNetworkRequest::setPipeliningAllowed(bool b) -
280{ -
281 d->pipeliningAllowed = b;
executed (the execution status of this line is deduced): d->pipeliningAllowed = b;
-
282}
executed: }
Execution Count:20
20
283 -
284bool QHttpNetworkRequest::withCredentials() const -
285{ -
286 return d->withCredentials;
executed: return d->withCredentials;
Execution Count:1289
1289
287} -
288 -
289void QHttpNetworkRequest::setWithCredentials(bool b) -
290{ -
291 d->withCredentials = b;
executed (the execution status of this line is deduced): d->withCredentials = b;
-
292}
executed: }
Execution Count:1
1
293 -
294void QHttpNetworkRequest::setUploadByteDevice(QNonContiguousByteDevice *bd) -
295{ -
296 d->uploadByteDevice = bd;
executed (the execution status of this line is deduced): d->uploadByteDevice = bd;
-
297}
executed: }
Execution Count:179
179
298 -
299QNonContiguousByteDevice* QHttpNetworkRequest::uploadByteDevice() const -
300{ -
301 return d->uploadByteDevice;
executed: return d->uploadByteDevice;
Execution Count:7902
7902
302} -
303 -
304int QHttpNetworkRequest::majorVersion() const -
305{ -
306 return 1;
executed: return 1;
Execution Count:859
859
307} -
308 -
309int QHttpNetworkRequest::minorVersion() const -
310{ -
311 return 1;
executed: return 1;
Execution Count:859
859
312} -
313 -
314 -
315QT_END_NAMESPACE -
316 -
317#endif -
318 -
319 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial