diff options
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r-- | rbutil/rbutilqt/base/httpget.cpp | 54 |
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) | |||
199 | 199 | ||
200 | // create hash used for caching | 200 | // create hash used for caching |
201 | m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex(); | 201 | m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex(); |
202 | m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash; | ||
202 | // RFC2616: the absoluteURI form must get used when the request is being | 203 | // RFC2616: the absoluteURI form must get used when the request is being |
203 | // sent to a proxy. | 204 | // sent to a proxy. |
204 | m_path.clear(); | 205 | m_path.clear(); |
@@ -211,7 +212,7 @@ bool HttpGet::getFile(const QUrl &url) | |||
211 | m_header.setValue("User-Agent", m_globalUserAgent); | 212 | m_header.setValue("User-Agent", m_globalUserAgent); |
212 | m_header.setValue("Connection", "Keep-Alive"); | 213 | m_header.setValue("Connection", "Keep-Alive"); |
213 | 214 | ||
214 | if(!m_usecache) { | 215 | if(!m_usecache || !QFileInfo(m_cachefile).exists()) { |
215 | getFileFinish(); | 216 | getFileFinish(); |
216 | } | 217 | } |
217 | else { | 218 | else { |
@@ -227,7 +228,6 @@ bool HttpGet::getFile(const QUrl &url) | |||
227 | 228 | ||
228 | void HttpGet::getFileFinish() | 229 | void HttpGet::getFileFinish() |
229 | { | 230 | { |
230 | m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash; | ||
231 | QString indexFile = m_cachedir.absolutePath() + "/rbutil-cache/cache.txt"; | 231 | QString indexFile = m_cachedir.absolutePath() + "/rbutil-cache/cache.txt"; |
232 | if(m_usecache) { | 232 | if(m_usecache) { |
233 | // check if the file is present in cache | 233 | // check if the file is present in cache |
@@ -347,35 +347,35 @@ void HttpGet::httpFinished(int id, bool error) | |||
347 | emit requestFinished(id, error); | 347 | emit requestFinished(id, error); |
348 | } | 348 | } |
349 | 349 | ||
350 | if(id == headRequest) { | 350 | QHttpResponseHeader h = http.lastResponse(); |
351 | QHttpResponseHeader h = http.lastResponse(); | 351 | QString date = h.value("Last-Modified").simplified(); |
352 | 352 | if(date.isEmpty()) { | |
353 | QString date = h.value("Last-Modified").simplified(); | 353 | m_serverTimestamp = QDateTime(); // no value = invalid |
354 | if(date.isEmpty()) { | 354 | if(id == headRequest) |
355 | m_serverTimestamp = QDateTime(); // no value = invalid | ||
356 | emit headerFinished(); | 355 | emit headerFinished(); |
357 | return; | ||
358 | } | ||
359 | // to successfully parse the date strip weekday and timezone | ||
360 | date.remove(0, date.indexOf(" ") + 1); | ||
361 | if(date.endsWith("GMT")) | ||
362 | date.truncate(date.indexOf(" GMT")); | ||
363 | // distinguish input formats (see RFC1945) | ||
364 | // RFC 850 | ||
365 | if(date.contains("-")) | ||
366 | m_serverTimestamp = QLocale::c().toDateTime(date, "dd-MMM-yy hh:mm:ss"); | ||
367 | // asctime format | ||
368 | else if(date.at(0).isLetter()) | ||
369 | m_serverTimestamp = QLocale::c().toDateTime(date, "MMM d hh:mm:ss yyyy"); | ||
370 | // RFC 822 | ||
371 | else | 356 | else |
372 | m_serverTimestamp = QLocale::c().toDateTime(date, "dd MMM yyyy hh:mm:ss"); | 357 | emit requestFinished(id, error); |
373 | qDebug() << "[HTTP] HEAD finished, server date:" << date << ", parsed:" << m_serverTimestamp; | ||
374 | emit headerFinished(); | ||
375 | return; | 358 | return; |
376 | } | 359 | } |
377 | if(id == getRequest) | 360 | // to successfully parse the date strip weekday and timezone |
361 | date.remove(0, date.indexOf(" ") + 1); | ||
362 | if(date.endsWith("GMT")) date.truncate(date.indexOf(" GMT")); | ||
363 | // distinguish input formats (see RFC1945) | ||
364 | if(date.contains("-")) // RFC 850 | ||
365 | m_serverTimestamp = QLocale::c().toDateTime(date, "dd-MMM-yy hh:mm:ss"); | ||
366 | else if(date.at(0).isLetter()) // asctime format | ||
367 | m_serverTimestamp = QLocale::c().toDateTime(date, "MMM d hh:mm:ss yyyy"); | ||
368 | else // RFC 822 | ||
369 | m_serverTimestamp = QLocale::c().toDateTime(date, "dd MMM yyyy hh:mm:ss"); | ||
370 | |||
371 | qDebug() << "[HTTP] file server date:" << date | ||
372 | << "parsed:" << m_serverTimestamp; | ||
373 | |||
374 | if(id == headRequest) | ||
375 | emit headerFinished(); | ||
376 | else | ||
378 | emit requestFinished(id, error); | 377 | emit requestFinished(id, error); |
378 | return; | ||
379 | } | 379 | } |
380 | 380 | ||
381 | void HttpGet::httpStarted(int id) | 381 | void HttpGet::httpStarted(int id) |
@@ -396,7 +396,7 @@ void HttpGet::httpResponseHeader(const QHttpResponseHeader &resp) | |||
396 | // if there is a network error abort all scheduled requests for | 396 | // if there is a network error abort all scheduled requests for |
397 | // this download | 397 | // this download |
398 | m_response = resp.statusCode(); | 398 | m_response = resp.statusCode(); |
399 | 399 | ||
400 | // 301 -- moved permanently | 400 | // 301 -- moved permanently |
401 | // 302 -- found | 401 | // 302 -- found |
402 | // 303 -- see other | 402 | // 303 -- see other |