2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "NetworkingContext.h"
22 #include "ResourceRequest.h"
23 #include "ThirdPartyCookiesQt.h"
27 #include <QNetworkRequest>
32 // The limit can be found in qhttpnetworkconnection.cpp.
33 // To achieve the best result we want WebKit to schedule the jobs so we
34 // are using the limit as found in Qt. To allow Qt to fill its queue
35 // and prepare jobs we will schedule two more downloads.
36 // Per TCP connection there is 1 current processed, 3 possibly pipelined
37 // and 2 ready to re-fill the pipeline.
38 unsigned initializeMaximumHTTPConnectionCountPerHost()
40 return 6 * (1 + 3 + 2);
43 QNetworkRequest ResourceRequest::toNetworkRequest(NetworkingContext *context) const
45 QNetworkRequest request;
46 request.setUrl(url());
47 request.setOriginatingObject(context ? context->originatingObject() : 0);
49 const HTTPHeaderMap &headers = httpHeaderFields();
50 for (HTTPHeaderMap::const_iterator it = headers.begin(), end = headers.end();
52 QByteArray name = QString(it->first).toAscii();
53 QByteArray value = QString(it->second).toAscii();
54 // QNetworkRequest::setRawHeader() would remove the header if the value is null
55 // Make sure to set an empty header instead of null header.
57 request.setRawHeader(name, value);
59 request.setRawHeader(name, "");
62 // Make sure we always have an Accept header; some sites require this to
64 if (!request.hasRawHeader("Accept"))
65 request.setRawHeader("Accept", "*/*");
67 switch (cachePolicy()) {
68 case ReloadIgnoringCacheData:
69 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
71 case ReturnCacheDataElseLoad:
72 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
74 case ReturnCacheDataDontLoad:
75 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
77 case UseProtocolCachePolicy:
78 // QNetworkRequest::PreferNetwork
83 if (!allowCookies() || !thirdPartyCookiePolicyPermits(context, url(), firstPartyForCookies())) {
84 request.setAttribute(QNetworkRequest::CookieSaveControlAttribute, QNetworkRequest::Manual);
85 request.setAttribute(QNetworkRequest::CookieLoadControlAttribute, QNetworkRequest::Manual);
89 request.setAttribute(QNetworkRequest::AuthenticationReuseAttribute, QNetworkRequest::Manual);