forked from len0rd/rockbox
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
This commit is contained in:
parent
4627d4b56e
commit
d24a9ea3b2
2 changed files with 26 additions and 2 deletions
|
|
@ -17,7 +17,6 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtNetwork>
|
#include <QtNetwork>
|
||||||
#include <QtDebug>
|
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
|
|
@ -155,7 +154,10 @@ void HttpGet::requestFinished(QNetworkReply* reply)
|
||||||
startRequest(url);
|
startRequest(url);
|
||||||
return;
|
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();
|
m_data = reply->readAll();
|
||||||
if(m_outputFile && m_outputFile->open(QIODevice::WriteOnly)) {
|
if(m_outputFile && m_outputFile->open(QIODevice::WriteOnly)) {
|
||||||
m_outputFile->write(m_data);
|
m_outputFile->write(m_data);
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,7 @@ class TestHttpGet : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
|
void testFileUrlRequest(void);
|
||||||
void testCachedRequest(void);
|
void testCachedRequest(void);
|
||||||
void testUncachedRepeatedRequest(void);
|
void testUncachedRepeatedRequest(void);
|
||||||
void testUncachedMovedRequest(void);
|
void testUncachedMovedRequest(void);
|
||||||
|
|
@ -188,6 +189,27 @@ void TestHttpGet::cleanup(void)
|
||||||
if(m_doneSpy) delete m_doneSpy;
|
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.
|
/* On uncached requests, HttpGet is supposed to sent a GET request only.
|
||||||
*/
|
*/
|
||||||
void TestHttpGet::testUncachedRepeatedRequest(void)
|
void TestHttpGet::testUncachedRepeatedRequest(void)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue