Home | History | Annotate | Download | only in qt
      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.
     35 // Per TCP connection there is 1 current processed, 3 possibly pipelined
     36 // and 2 ready to re-fill the pipeline.
     37 unsigned initializeMaximumHTTPConnectionCountPerHost()
     38 {
     39 #ifdef Q_OS_SYMBIAN
     40     return 3 * (1 + 3 + 2);
     41 #else
     42     return 6 * (1 + 3 + 2);
     43 #endif
     44 }
     45 
     46 QNetworkRequest ResourceRequest::toNetworkRequest(QObject* originatingFrame) const
     47 {
     48     QNetworkRequest request;
     49     request.setUrl(url());
     50     request.setOriginatingObject(originatingFrame);
     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     // Make sure we always have an Accept header; some sites require this to
     66     // serve subresources
     67     if (!request.hasRawHeader("Accept"))
     68         request.setRawHeader("Accept", "*/*");
     69 
     70     switch (cachePolicy()) {
     71     case ReloadIgnoringCacheData:
     72         request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
     73         break;
     74     case ReturnCacheDataElseLoad:
     75         request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
     76         break;
     77     case ReturnCacheDataDontLoad:
     78         request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
     79         break;
     80     case UseProtocolCachePolicy:
     81         // QNetworkRequest::PreferNetwork
     82     default:
     83         break;
     84     }
     85 
     86     if (!allowCookies()) {
     87         request.setAttribute(QNetworkRequest::CookieLoadControlAttribute, QNetworkRequest::Manual);
     88         request.setAttribute(QNetworkRequest::CookieSaveControlAttribute, QNetworkRequest::Manual);
     89         request.setAttribute(QNetworkRequest::AuthenticationReuseAttribute, QNetworkRequest::Manual);
     90     }
     91 
     92     return request;
     93 }
     94 
     95 }
     96 
     97