summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/httpget.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2013-01-22 20:34:33 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2013-01-22 20:39:40 +0100
commit554ee364b0ab37fec2c2a83a93a466cb10025230 (patch)
tree7fa927a2ff9a8ad31723f35d171c26b516079824 /rbutil/rbutilqt/base/httpget.cpp
parenta2ab22efbf93981f9a86b6b06dc6d3c2f1167728 (diff)
downloadrockbox-554ee364b0ab37fec2c2a83a93a466cb10025230.tar.gz
rockbox-554ee364b0ab37fec2c2a83a93a466cb10025230.tar.bz2
rockbox-554ee364b0ab37fec2c2a83a93a466cb10025230.zip
Avoid unnecessary HEAD request on uncached file.
If a file is not available in the cache immediately sent a GET request. Using a HEAD request to retrieve the file timestamp on the server is not necessary and only creates an unnecessary network request. Change-Id: I358507dcc0c6b837ff47e5fd710b5262d03cb7b0
Diffstat (limited to 'rbutil/rbutilqt/base/httpget.cpp')
-rw-r--r--rbutil/rbutilqt/base/httpget.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/rbutil/rbutilqt/base/httpget.cpp b/rbutil/rbutilqt/base/httpget.cpp
index 66a7076391..58f6bd5e09 100644
--- a/rbutil/rbutilqt/base/httpget.cpp
+++ b/rbutil/rbutilqt/base/httpget.cpp
@@ -199,6 +199,7 @@ bool HttpGet::getFile(const QUrl &url)
// create hash used for caching
m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex();
+ m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash;
// RFC2616: the absoluteURI form must get used when the request is being
// sent to a proxy.
m_path.clear();
@@ -211,7 +212,7 @@ bool HttpGet::getFile(const QUrl &url)
m_header.setValue("User-Agent", m_globalUserAgent);
m_header.setValue("Connection", "Keep-Alive");
- if(!m_usecache) {
+ if(!m_usecache || !QFileInfo(m_cachefile).exists()) {
getFileFinish();
}
else {
@@ -227,7 +228,6 @@ bool HttpGet::getFile(const QUrl &url)
void HttpGet::getFileFinish()
{
- m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash;
QString indexFile = m_cachedir.absolutePath() + "/rbutil-cache/cache.txt";
if(m_usecache) {
// check if the file is present in cache
@@ -347,35 +347,35 @@ void HttpGet::httpFinished(int id, bool error)
emit requestFinished(id, error);
}
- if(id == headRequest) {
- QHttpResponseHeader h = http.lastResponse();
-
- QString date = h.value("Last-Modified").simplified();
- if(date.isEmpty()) {
- m_serverTimestamp = QDateTime(); // no value = invalid
+ QHttpResponseHeader h = http.lastResponse();
+ QString date = h.value("Last-Modified").simplified();
+ if(date.isEmpty()) {
+ m_serverTimestamp = QDateTime(); // no value = invalid
+ if(id == headRequest)
emit headerFinished();
- return;
- }
- // to successfully parse the date strip weekday and timezone
- date.remove(0, date.indexOf(" ") + 1);
- if(date.endsWith("GMT"))
- date.truncate(date.indexOf(" GMT"));
- // distinguish input formats (see RFC1945)
- // RFC 850
- if(date.contains("-"))
- m_serverTimestamp = QLocale::c().toDateTime(date, "dd-MMM-yy hh:mm:ss");
- // asctime format
- else if(date.at(0).isLetter())
- m_serverTimestamp = QLocale::c().toDateTime(date, "MMM d hh:mm:ss yyyy");
- // RFC 822
else
- m_serverTimestamp = QLocale::c().toDateTime(date, "dd MMM yyyy hh:mm:ss");
- qDebug() << "[HTTP] HEAD finished, server date:" << date << ", parsed:" << m_serverTimestamp;
- emit headerFinished();
+ emit requestFinished(id, error);
return;
}
- if(id == getRequest)
+ // to successfully parse the date strip weekday and timezone
+ date.remove(0, date.indexOf(" ") + 1);
+ if(date.endsWith("GMT")) date.truncate(date.indexOf(" GMT"));
+ // distinguish input formats (see RFC1945)
+ if(date.contains("-")) // RFC 850
+ m_serverTimestamp = QLocale::c().toDateTime(date, "dd-MMM-yy hh:mm:ss");
+ else if(date.at(0).isLetter()) // asctime format
+ m_serverTimestamp = QLocale::c().toDateTime(date, "MMM d hh:mm:ss yyyy");
+ else // RFC 822
+ m_serverTimestamp = QLocale::c().toDateTime(date, "dd MMM yyyy hh:mm:ss");
+
+ qDebug() << "[HTTP] file server date:" << date
+ << "parsed:" << m_serverTimestamp;
+
+ if(id == headRequest)
+ emit headerFinished();
+ else
emit requestFinished(id, error);
+ return;
}
void HttpGet::httpStarted(int id)
@@ -396,7 +396,7 @@ void HttpGet::httpResponseHeader(const QHttpResponseHeader &resp)
// if there is a network error abort all scheduled requests for
// this download
m_response = resp.statusCode();
-
+
// 301 -- moved permanently
// 302 -- found
// 303 -- see other