Started moving the code to separate a WebCore::ResourceRequest into a QUrl, postData
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jun 2007 13:48:58 +0000 (13:48 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jun 2007 13:48:58 +0000 (13:48 +0000)
and QHttpRequestHeader into a separate little QWebNetworkRequest struct.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@22091 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitQt/Api/qwebnetworkinterface.cpp
WebKitQt/Api/qwebnetworkinterface_p.h
WebKitQt/Api/qwebobjectpluginconnector.cpp
WebKitQt/ChangeLog

index 8e4b3e00e2ce25f6fbe1d8566588a47125faeeec..4ef0a83d7aea92412b5d1a27b07d8209a3e8d869 100644 (file)
@@ -56,7 +56,25 @@ static bool operator==(const HostInfo &i1, const HostInfo &i2)
     return i1.port == i2.port && i1.host == i2.host;
 }
 
-void QWebNetworkJobPrivate::setURL(const QUrl &u)
+void QWebNetworkRequest::init(const QString &method, const QUrl &url, const WebCore::ResourceRequest *resourceRequest)
+{
+    request = QHttpRequestHeader(method, url.toEncoded(QUrl::RemoveScheme|QUrl::RemoveAuthority));
+    request.setValue(QLatin1String("User-Agent"),
+                             QLatin1String("Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)"));
+    request.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
+    setURL(url);
+
+    if (resourceRequest) {
+        const QString scheme = url.scheme().toLower();
+        if (scheme == QLatin1String("http") || scheme == QLatin1String("https")) {
+            QString cookies = WebCore::cookies(resourceRequest->url());
+            if (!cookies.isEmpty())
+                request.setValue(QLatin1String("Cookie"), cookies);
+        }
+    }
+}
+
+void QWebNetworkRequest::setURL(const QUrl &u)
 {
     url = u;
     int port = url.port();
@@ -66,15 +84,6 @@ void QWebNetworkJobPrivate::setURL(const QUrl &u)
         request.setValue(QLatin1String("Host"), url.host());
 }
 
-void QWebNetworkJobPrivate::setDefaults(const QString &method, const QUrl &url)
-{
-    request = QHttpRequestHeader(method, url.toEncoded(QUrl::RemoveScheme|QUrl::RemoveAuthority));
-    request.setValue(QLatin1String("User-Agent"),
-                             QLatin1String("Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)"));
-    request.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
-    setURL(url);
-}
-
 /*!
   \class QWebNetworkJob
 
@@ -225,15 +234,8 @@ bool QWebNetworkManager::add(ResourceHandle *handle, QWebNetworkInterface *inter
 
     KURL url = handle->url();
     QUrl qurl = QString(url.url());
-    job->d->setDefaults(handle->method(), qurl);
+    job->d->init(handle->method(), qurl, &handle->request());
 
-    const QString scheme = qurl.scheme().toLower();
-    if (scheme == QLatin1String("http") || scheme == QLatin1String("https")) {
-        QString cookies = WebCore::cookies(handle->url());
-        if (!cookies.isEmpty())
-            job->d->request.setValue(QLatin1String("Cookie"), cookies);
-    }
-    
     const HTTPHeaderMap& loaderHeaders = handle->requestHeaders();
     HTTPHeaderMap::const_iterator end = loaderHeaders.end();
     for (HTTPHeaderMap::const_iterator it = loaderHeaders.begin(); it != end; ++it)
index 24160b5664fa2745163255df25a6048802429d11..e68f334f7964d92c39cf8311a70bfc66da4eb6c7 100644 (file)
@@ -27,6 +27,7 @@
 
 namespace WebCore {
     struct HostInfo;
+    class ResourceRequest;
 };
 uint qHash(const WebCore::HostInfo &info);
 #include <qhash.h>
@@ -35,7 +36,17 @@ namespace WebCore {
     class ResourceHandle;
 }
 
-class QWebNetworkJobPrivate
+struct QWebNetworkRequest
+{
+    QUrl url;
+    QHttpRequestHeader request;
+    QByteArray postData;
+
+    void init(const QString &method, const QUrl &url, const WebCore::ResourceRequest *resourceRequest = 0);
+    void setURL(const QUrl &u);
+};
+
+class QWebNetworkJobPrivate : public QWebNetworkRequest
 {
 public:
     QWebNetworkJobPrivate()
@@ -46,9 +57,6 @@ public:
         , connector(0)
         {}
     int ref;
-    QUrl url;
-    QHttpRequestHeader request;
-    QByteArray postData;
 
     QHttpResponseHeader response;
 
@@ -57,9 +65,6 @@ public:
 
     QWebNetworkInterface *interface;
     QWebObjectPluginConnector *connector;
-
-    void setURL(const QUrl &u);
-    void setDefaults(const QString &method, const QUrl &url);
 };
 
 
index 1554a5c292315b419aa84d23a51acc091305db79..9bd3d231fb02f4c53f88d65833eff27bde416d9c 100644 (file)
@@ -56,7 +56,7 @@ QWebNetworkJob *QWebObjectPluginConnector::requestUrl(QWebNetworkJob::Method met
     p->connector = this;
 
     QString m = (method == QWebNetworkJob::Get ? "GET" : "POST");
-    p->setDefaults(m, url);
+    p->init(m, url);
 
     d->frame->page()->networkInterface()->addJob(job);
     return job;
index 350316069720a5239b18fd503f2f3a0493bdf221..008f2666e11eb803d5656a2b1af1af37c334ac1d 100644 (file)
@@ -1,3 +1,17 @@
+2007-06-11  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Started moving the code to separate a WebCore::ResourceRequest into a QUrl, postData
+        and QHttpRequestHeader into a separate little QWebNetworkRequest struct.
+
+        * Api/qwebnetworkinterface.cpp:
+        (QWebNetworkRequest::init):
+        (QWebNetworkManager::add):
+        * Api/qwebnetworkinterface_p.h:
+        * Api/qwebobjectpluginconnector.cpp:
+        (QWebObjectPluginConnector::requestUrl):
+
 2007-06-11  Zack Rusin <zrusin@trolltech.com>
 
         Reviewed by Lars