1 /*
2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3
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.
8
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.
13
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.
18 */
19
20 #include "config.h"
21 #include "ResourceRequest.h"
22
23 #include <qglobal.h>
24
25 #include <QNetworkRequest>
26 #include <QUrl>
27
28 namespace WebCore {
29
30 // Currently Qt allows three connections per host on symbian and six
31 // for everyone else. The limit can be found in qhttpnetworkconnection.cpp.
32 // To achieve the best result we want WebKit to schedule the jobs so we
33 // are using the limit as found in Qt. To allow Qt to fill its queue
34 // and prepare jobs we will schedule two more downloads.
initializeMaximumHTTPConnectionCountPerHost()35 unsigned initializeMaximumHTTPConnectionCountPerHost()
36 {
37 #ifdef Q_OS_SYMBIAN
38 return 3 + 2;
39 #else
40 return 6 + 2;
41 #endif
42 }
43
toNetworkRequest(QObject * originatingFrame) const44 QNetworkRequest ResourceRequest::toNetworkRequest(QObject* originatingFrame) const
45 {
46 QNetworkRequest request;
47 request.setUrl(url());
48 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
49 request.setOriginatingObject(originatingFrame);
50 #endif
51
52 const HTTPHeaderMap &headers = httpHeaderFields();
53 for (HTTPHeaderMap::const_iterator it = headers.begin(), end = headers.end();
54 it != end; ++it) {
55 QByteArray name = QString(it->first).toAscii();
56 QByteArray value = QString(it->second).toAscii();
57 // QNetworkRequest::setRawHeader() would remove the header if the value is null
58 // Make sure to set an empty header instead of null header.
59 if (!value.isNull())
60 request.setRawHeader(name, value);
61 else
62 request.setRawHeader(name, "");
63 }
64
65 switch (cachePolicy()) {
66 case ReloadIgnoringCacheData:
67 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
68 break;
69 case ReturnCacheDataElseLoad:
70 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
71 break;
72 case ReturnCacheDataDontLoad:
73 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
74 break;
75 case UseProtocolCachePolicy:
76 // QNetworkRequest::PreferNetwork
77 default:
78 break;
79 }
80
81 return request;
82 }
83
84 }
85
86