qhttpnetworkrequest.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/access/qhttpnetworkrequest.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op,-
7 QHttpNetworkRequest::Priority pri, const QUrl &newUrl)-
8 : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(0),-
9 autoDecompress(false), pipeliningAllowed(false), spdyAllowed(false),-
10 withCredentials(true), preConnect(false), followRedirect(false), redirectCount(0)-
11{-
12}-
13-
14QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(const QHttpNetworkRequestPrivate &other)-
15 : QHttpNetworkHeaderPrivate(other)-
{),
16 operation=(other.operation;),-
17 customVerb(other.customVerb),-
18 priority=(other.priority;),-
19 uploadByteDevice=(other.uploadByteDevice;),-
20 autoDecompress=(other.autoDecompress;),-
21 pipeliningAllowed=(other.pipeliningAllowed;),-
22 spdyAllowed=(other.spdyAllowed;-
customVerb = other.customVerb;),
23 withCredentials=(other.withCredentials;),-
24 ssl=(other.ssl;),-
25 preConnect=(other.preConnect;),-
26 followRedirect=(other.followRedirect;),-
27 redirectCount=(other.redirectCount;)-
28{-
29}
executed 2184 times by 8 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkDiskCache
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
2184
30-
31QHttpNetworkRequestPrivate::~QHttpNetworkRequestPrivate()-
32{-
33}-
34-
35bool QHttpNetworkRequestPrivate::operator==(const QHttpNetworkRequestPrivate &other) const-
36{-
37 return QHttpNetworkHeaderPrivate::operator==(other)-
38 && (operation == other.operation)-
39 && (priority == other.priority)-
40 && (uploadByteDevice == other.uploadByteDevice)-
41 && (autoDecompress == other.autoDecompress)-
42 && (pipeliningAllowed == other.pipeliningAllowed)-
43 && (spdyAllowed == other.spdyAllowed)-
44-
45 && (operation != QHttpNetworkRequest::Custom || (customVerb == other.customVerb))-
46 && (withCredentials == other.withCredentials)-
47 && (ssl == other.ssl)-
48 && (preConnect == other.preConnect);-
49}-
50-
51QByteArray QHttpNetworkRequest::methodName() const-
52{-
53 switch (d->operation) {-
54 case QHttpNetworkRequest::Get:-
55 return "GET";-
56 case QHttpNetworkRequest::Head:-
57 return "HEAD";-
58 case QHttpNetworkRequest::Post:-
59 return "POST";-
60 case QHttpNetworkRequest::Options:-
61 return "OPTIONS";-
62 case QHttpNetworkRequest::Put:-
63 return "PUT";-
64 case QHttpNetworkRequest::Delete:-
65 return "DELETE";-
66 case QHttpNetworkRequest::Trace:-
67 return "TRACE";-
68 case QHttpNetworkRequest::Connect:-
69 return "CONNECT";-
70 case QHttpNetworkRequest::Custom:-
71 return d->customVerb;-
72 default:-
73 break;-
74 }-
75 return QByteArray();-
76}-
77-
78QByteArray QHttpNetworkRequest::uri(bool throughProxy) const-
79{-
80 QUrl::FormattingOptions format(QUrl::RemoveFragment | QUrl::RemoveUserInfo | QUrl::FullyEncoded);-
81-
82-
83 if (d->operation == QHttpNetworkRequest::Post && !d->uploadByteDevice)-
84 format |= QUrl::RemoveQuery;-
85-
86 if (!throughProxy)-
87 format |= QUrl::RemoveScheme | QUrl::RemoveAuthority;-
88 QUrl copy = d->url;-
89 if (copy.path().isEmpty())-
90 copy.setPath(([]() -> QString { enum { Size = sizeof(u"" "/")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));-
91 QByteArray uri = copy.toEncoded(format);-
92 return uri;-
93}-
94-
95QByteArray QHttpNetworkRequestPrivate::header(const QHttpNetworkRequest &request, bool throughProxy)-
96{-
97 QList<QPair<QByteArray, QByteArray> > fields = request.header();-
98 QByteArray ba;-
99 ba.reserve(40 + fields.length()*25);-
100-
101 ba += request.methodName();-
102 ba += ' ';-
103 ba += request.uri(throughProxy);-
104-
105 ba += " HTTP/";-
106 ba += QByteArray::number(request.majorVersion());-
107 ba += '.';-
108 ba += QByteArray::number(request.minorVersion());-
109 ba += "\r\n";-
110-
111 QList<QPair<QByteArray, QByteArray> >::const_iterator it = fields.constBegin();-
112 QList<QPair<QByteArray, QByteArray> >::const_iterator endIt = fields.constEnd();-
113 for (; it != endIt; ++it) {-
114 ba += it->first;-
115 ba += ": ";-
116 ba += it->second;-
117 ba += "\r\n";-
118 }-
119 if (request.d->operation == QHttpNetworkRequest::Post) {-
120-
121 if (request.headerField("content-type").isEmpty() && ((request.d->uploadByteDevice && request.d->uploadByteDevice->size() > 0) || request.d->url.hasQuery())) {-
122-
123-
124-
125 QMessageLogger(__FILE__, 160166, __PRETTY_FUNCTION__).warning("content-type missing in HTTP POST, defaulting to application/x-www-form-urlencoded. Use QNetworkRequest::setHeader() to fix this problem.");-
126 ba += "Content-Type: application/x-www-form-urlencoded\r\n";-
127 }-
128 if (!request.d->uploadByteDevice && request.d->url.hasQuery()) {-
129 QByteArray query = request.d->url.query(QUrl::FullyEncoded).toLatin1();-
130 ba += "Content-Length: ";-
131 ba += QByteArray::number(query.size());-
132 ba += "\r\n\r\n";-
133 ba += query;-
134 } else {-
135 ba += "\r\n";-
136 }-
137 } else {-
138 ba += "\r\n";-
139 }-
140 return ba;-
141}-
142-
143-
144-
145-
146QHttpNetworkRequest::QHttpNetworkRequest(const QUrl &url, Operation operation, Priority priority)-
147 : d(new QHttpNetworkRequestPrivate(operation, priority, url))-
148{-
149}-
150-
151QHttpNetworkRequest::QHttpNetworkRequest(const QHttpNetworkRequest &other)-
152 : QHttpNetworkHeader(other), d(other.d)-
153{-
154}-
155-
156QHttpNetworkRequest::~QHttpNetworkRequest()-
157{-
158}-
159-
160QUrl QHttpNetworkRequest::url() const-
161{-
162 return d->url;-
163}-
164void QHttpNetworkRequest::setUrl(const QUrl &url)-
165{-
166 d->url = url;-
167}-
168-
169bool QHttpNetworkRequest::isSsl() const-
170{-
171 return d->ssl;-
172}-
173void QHttpNetworkRequest::setSsl(bool s)-
174{-
175 d->ssl = s;-
176}-
177-
178bool QHttpNetworkRequest::isPreConnect() const-
179{-
180 return d->preConnect;-
181}-
182void QHttpNetworkRequest::setPreConnect(bool preConnect)-
183{-
184 d->preConnect = preConnect;-
185}-
186-
187bool QHttpNetworkRequest::isFollowRedirects() const-
188{-
189 return d->followRedirect;-
190}-
191-
192void QHttpNetworkRequest::setFollowRedirects(bool followRedirect)-
193{-
194 d->followRedirect = followRedirect;-
195}-
196-
197int QHttpNetworkRequest::redirectCount() const-
198{-
199 return d->redirectCount;-
200}-
201-
202void QHttpNetworkRequest::setRedirectCount(int count)-
203{-
204 d->redirectCount = count;-
205}-
206-
207qint64 QHttpNetworkRequest::contentLength() const-
208{-
209 return d->contentLength();-
210}-
211-
212void QHttpNetworkRequest::setContentLength(qint64 length)-
213{-
214 d->setContentLength(length);-
215}-
216-
217QList<QPair<QByteArray, QByteArray> > QHttpNetworkRequest::header() const-
218{-
219 return d->fields;-
220}-
221-
222QByteArray QHttpNetworkRequest::headerField(const QByteArray &name, const QByteArray &defaultValue) const-
223{-
224 return d->headerField(name, defaultValue);-
225}-
226-
227void QHttpNetworkRequest::setHeaderField(const QByteArray &name, const QByteArray &data)-
228{-
229 d->setHeaderField(name, data);-
230}-
231-
232QHttpNetworkRequest &QHttpNetworkRequest::operator=(const QHttpNetworkRequest &other)-
233{-
234 d = other.d;-
235 return *this;-
236}-
237-
238bool QHttpNetworkRequest::operator==(const QHttpNetworkRequest &other) const-
239{-
240 return d->operator==(*other.d);-
241}-
242-
243QHttpNetworkRequest::Operation QHttpNetworkRequest::operation() const-
244{-
245 return d->operation;-
246}-
247-
248void QHttpNetworkRequest::setOperation(Operation operation)-
249{-
250 d->operation = operation;-
251}-
252-
253QByteArray QHttpNetworkRequest::customVerb() const-
254{-
255 return d->customVerb;-
256}-
257-
258void QHttpNetworkRequest::setCustomVerb(const QByteArray &customVerb)-
259{-
260 d->customVerb = customVerb;-
261}-
262-
263QHttpNetworkRequest::Priority QHttpNetworkRequest::priority() const-
264{-
265 return d->priority;-
266}-
267-
268void QHttpNetworkRequest::setPriority(Priority priority)-
269{-
270 d->priority = priority;-
271}-
272-
273bool QHttpNetworkRequest::isPipeliningAllowed() const-
274{-
275 return d->pipeliningAllowed;-
276}-
277-
278void QHttpNetworkRequest::setPipeliningAllowed(bool b)-
279{-
280 d->pipeliningAllowed = b;-
281}-
282-
283bool QHttpNetworkRequest::isSPDYAllowed() const-
284{-
285 return d->spdyAllowed;-
286}-
287-
288void QHttpNetworkRequest::setSPDYAllowed(bool b)-
289{-
290 d->spdyAllowed = b;-
291}-
292-
293bool QHttpNetworkRequest::withCredentials() const-
294{-
295 return d->withCredentials;-
296}-
297-
298void QHttpNetworkRequest::setWithCredentials(bool b)-
299{-
300 d->withCredentials = b;-
301}-
302-
303void QHttpNetworkRequest::setUploadByteDevice(QNonContiguousByteDevice *bd)-
304{-
305 d->uploadByteDevice = bd;-
306}-
307-
308QNonContiguousByteDevice* QHttpNetworkRequest::uploadByteDevice() const-
309{-
310 return d->uploadByteDevice;-
311}-
312-
313int QHttpNetworkRequest::majorVersion() const-
314{-
315 return 1;-
316}-
317-
318int QHttpNetworkRequest::minorVersion() const-
319{-
320 return 1;-
321}-
322-
323-
324-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9