diff options
-rw-r--r-- | rbutil/rbutilqt/base/httpget.cpp | 6 | ||||
-rw-r--r-- | rbutil/rbutilqt/test/test-httpget.cpp | 22 |
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 @@ | |||
17 | ****************************************************************************/ | 17 | ****************************************************************************/ |
18 | 18 | ||
19 | #include <QtNetwork> | 19 | #include <QtNetwork> |
20 | #include <QtDebug> | ||
21 | 20 | ||
22 | #include <QNetworkAccessManager> | 21 | #include <QNetworkAccessManager> |
23 | #include <QNetworkRequest> | 22 | #include <QNetworkRequest> |
@@ -155,7 +154,10 @@ void HttpGet::requestFinished(QNetworkReply* reply) | |||
155 | startRequest(url); | 154 | startRequest(url); |
156 | return; | 155 | return; |
157 | } | 156 | } |
158 | else if(m_lastStatusCode == 200) { | 157 | else if(m_lastStatusCode == 200 || |
158 | (reply->url().isLocalFile() && reply->error() == 0)) { | ||
159 | // callers might not be aware if the request is file:// so fake 200. | ||
160 | m_lastStatusCode = 200; | ||
159 | m_data = reply->readAll(); | 161 | m_data = reply->readAll(); |
160 | if(m_outputFile && m_outputFile->open(QIODevice::WriteOnly)) { | 162 | if(m_outputFile && m_outputFile->open(QIODevice::WriteOnly)) { |
161 | m_outputFile->write(m_data); | 163 | 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 | |||
118 | { | 118 | { |
119 | Q_OBJECT | 119 | Q_OBJECT |
120 | private slots: | 120 | private slots: |
121 | void testFileUrlRequest(void); | ||
121 | void testCachedRequest(void); | 122 | void testCachedRequest(void); |
122 | void testUncachedRepeatedRequest(void); | 123 | void testUncachedRepeatedRequest(void); |
123 | void testUncachedMovedRequest(void); | 124 | void testUncachedMovedRequest(void); |
@@ -188,6 +189,27 @@ void TestHttpGet::cleanup(void) | |||
188 | if(m_doneSpy) delete m_doneSpy; | 189 | if(m_doneSpy) delete m_doneSpy; |
189 | } | 190 | } |
190 | 191 | ||
192 | void TestHttpGet::testFileUrlRequest(void) | ||
193 | { | ||
194 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
195 | |||
196 | QString teststring = "The quick brown fox jumps over the lazy dog."; | ||
197 | QTemporaryFile datafile; | ||
198 | datafile.open(); | ||
199 | datafile.write(teststring.toLatin1()); | ||
200 | m_getter->getFile("file://" + datafile.fileName()); | ||
201 | datafile.close(); | ||
202 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
203 | QCoreApplication::processEvents(); | ||
204 | |||
205 | QCOMPARE(m_doneSpy->count(), 1); | ||
206 | QCOMPARE(m_waitTimeoutOccured, false); | ||
207 | QCOMPARE(m_daemon->lastRequestData().size(), 0); | ||
208 | QCOMPARE(m_getter->readAll(), teststring.toLatin1()); | ||
209 | QCOMPARE(m_getter->httpResponse(), 200); | ||
210 | } | ||
211 | |||
212 | |||
191 | /* On uncached requests, HttpGet is supposed to sent a GET request only. | 213 | /* On uncached requests, HttpGet is supposed to sent a GET request only. |
192 | */ | 214 | */ |
193 | void TestHttpGet::testUncachedRepeatedRequest(void) | 215 | void TestHttpGet::testUncachedRepeatedRequest(void) |