summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2015-12-18 23:05:13 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2015-12-18 23:42:17 +0100
commitd24a9ea3b2eaec28e44608bfc50d02cb14cea51b (patch)
tree9eb2bf3a52559b1b45d7f226fab03bb660f42b07
parent4627d4b56e63e5689ad6ffd652636f112081a0ea (diff)
downloadrockbox-d24a9ea3b2eaec28e44608bfc50d02cb14cea51b.tar.gz
rockbox-d24a9ea3b2eaec28e44608bfc50d02cb14cea51b.tar.bz2
rockbox-d24a9ea3b2eaec28e44608bfc50d02cb14cea51b.zip
Add support file:// URLs in HttpGet.
QNetworkAccessManager can handle file:// URLs without additional work. Make HttpGet aware of that so you can now also use it to retrieve file:// URLs. Add a unit test for it as well. Change-Id: If64b57453460b70bca9e5b0c725bb78344617bcd
-rw-r--r--rbutil/rbutilqt/base/httpget.cpp6
-rw-r--r--rbutil/rbutilqt/test/test-httpget.cpp22
2 files changed, 26 insertions, 2 deletions
diff --git a/rbutil/rbutilqt/base/httpget.cpp b/rbutil/rbutilqt/base/httpget.cpp
index 4b08faf33b..4d10301bc0 100644
--- a/rbutil/rbutilqt/base/httpget.cpp
+++ b/rbutil/rbutilqt/base/httpget.cpp
@@ -17,7 +17,6 @@
****************************************************************************/
#include <QtNetwork>
-#include <QtDebug>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
@@ -155,7 +154,10 @@ void HttpGet::requestFinished(QNetworkReply* reply)
startRequest(url);
return;
}
- else if(m_lastStatusCode == 200) {
+ else if(m_lastStatusCode == 200 ||
+ (reply->url().isLocalFile() && reply->error() == 0)) {
+ // callers might not be aware if the request is file:// so fake 200.
+ m_lastStatusCode = 200;
m_data = reply->readAll();
if(m_outputFile && m_outputFile->open(QIODevice::WriteOnly)) {
m_outputFile->write(m_data);
diff --git a/rbutil/rbutilqt/test/test-httpget.cpp b/rbutil/rbutilqt/test/test-httpget.cpp
index c9ae86bc6c..a062203e70 100644
--- a/rbutil/rbutilqt/test/test-httpget.cpp
+++ b/rbutil/rbutilqt/test/test-httpget.cpp
@@ -118,6 +118,7 @@ class TestHttpGet : public QObject
{
Q_OBJECT
private slots:
+ void testFileUrlRequest(void);
void testCachedRequest(void);
void testUncachedRepeatedRequest(void);
void testUncachedMovedRequest(void);
@@ -188,6 +189,27 @@ void TestHttpGet::cleanup(void)
if(m_doneSpy) delete m_doneSpy;
}
+void TestHttpGet::testFileUrlRequest(void)
+{
+ QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
+
+ QString teststring = "The quick brown fox jumps over the lazy dog.";
+ QTemporaryFile datafile;
+ datafile.open();
+ datafile.write(teststring.toLatin1());
+ m_getter->getFile("file://" + datafile.fileName());
+ datafile.close();
+ while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
+ QCoreApplication::processEvents();
+
+ QCOMPARE(m_doneSpy->count(), 1);
+ QCOMPARE(m_waitTimeoutOccured, false);
+ QCOMPARE(m_daemon->lastRequestData().size(), 0);
+ QCOMPARE(m_getter->readAll(), teststring.toLatin1());
+ QCOMPARE(m_getter->httpResponse(), 200);
+}
+
+
/* On uncached requests, HttpGet is supposed to sent a GET request only.
*/
void TestHttpGet::testUncachedRepeatedRequest(void)