diff ui/downloader.cpp @ 46:d28e2624c1d5

Reset connection before the next request. This makes the downloader work for the first simple test.
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 17 Mar 2014 10:51:47 +0000
parents c6125d73faf4
children 09cd242d8443
line wrap: on
line diff
--- a/ui/downloader.cpp	Fri Mar 14 16:40:53 2014 +0000
+++ b/ui/downloader.cpp	Mon Mar 17 10:51:47 2014 +0000
@@ -22,9 +22,6 @@
 #define MAX_SW_SIZE 10485760
 #define MAX_LIST_SIZE 1048576
 
-#define LIST_RESOURCE "/incoming/aheinecke/test"
-#define SW_RESOURCE "/incoming/aheinecke/test"
-
 
 Downloader::Downloader(QObject* parent, const QString& url,
                        const QByteArray& certificate,
@@ -73,9 +70,7 @@
     QTextStream responseStream(&response);
     QLocale cLocale = QLocale::c();
     QString headRequest =
-        QString::fromLatin1("HEAD %1 HTTP/1.1\r\n"
-                "Connection: Keep-Alive\r\n"
-                "\r\n\r\n").arg(resource);
+        QString::fromLatin1("HEAD %1 HTTP/1.0\r\n\r\n").arg(resource);
 
     ret = mSSLConnection.write(headRequest.toUtf8());
     if (ret != 0) {
@@ -104,7 +99,7 @@
             }
         }
     }
-
+    qDebug() << "Response: " << response;
     emit error (tr("Invalid response from the server"), SSLConnection::InvalidResponse);
     return QDateTime();
 }
@@ -116,7 +111,7 @@
     int ret = -1;
     size_t bytesRead = 0;
     QString getRequest =
-        QString::fromLatin1("GET %1 HTTP/1.1\r\n\r\n").arg(resource);
+        QString::fromLatin1("GET %1 HTTP/1.0\r\n\r\n").arg(resource);
 
     QSaveFile outputFile(fileName);
 
@@ -134,19 +129,20 @@
     }
 
     do {
+        /* Read the response in 8KiB chunks */
         QByteArray response = mSSLConnection.read(8192);
         if (response.isNull()) {
             qDebug() << "Error reading response";
             emit error(tr("Connection lost"), SSLConnection::ConnectionLost);
             return false;
         }
-        if (response.isEmpty()) {
-            /* We have read everything there is to read */
+        outputFile.write(response);
+        qDebug() << "Wrote: "<< response.size();
+        bytesRead += response.size();
+        if (response.size() < 8192) {
+            /* Nothing more to read for us */
             break;
         }
-
-        outputFile.write(response);
-        bytesRead += response.size();
     } while (bytesRead < maxSize);
 
     return outputFile.commit();
@@ -194,8 +190,7 @@
 
         qDebug() << "fileName: " << fileName;
 
-        if (!downloadFile(QString::fromLatin1(SW_RESOURCE),
-                   fileName, MAX_SW_SIZE)) {
+        if (!downloadFile(mResourceSW, fileName, MAX_SW_SIZE)) {
             return;
         }
 
@@ -214,8 +209,7 @@
 
         qDebug() << "fileName: " << fileName;
 
-        if (!downloadFile(QString::fromLatin1(LIST_RESOURCE),
-                   fileName, MAX_LIST_SIZE)) {
+        if (!downloadFile(mResourceList, fileName, MAX_LIST_SIZE)) {
             return;
         }
 

http://wald.intevation.org/projects/trustbridge/