diff options
Diffstat (limited to 'rbutil/rbutilqt/httpget.cpp')
-rw-r--r-- | rbutil/rbutilqt/httpget.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/rbutil/rbutilqt/httpget.cpp b/rbutil/rbutilqt/httpget.cpp index b349a2f4be..129545d158 100644 --- a/rbutil/rbutilqt/httpget.cpp +++ b/rbutil/rbutilqt/httpget.cpp | |||
@@ -26,6 +26,7 @@ | |||
26 | QDir HttpGet::m_globalCache; //< global cach path value for new objects | 26 | QDir HttpGet::m_globalCache; //< global cach path value for new objects |
27 | QUrl HttpGet::m_globalProxy; //< global proxy value for new objects | 27 | QUrl HttpGet::m_globalProxy; //< global proxy value for new objects |
28 | bool HttpGet::m_globalDumbCache = false; //< globally set cache "dumb" mode | 28 | bool HttpGet::m_globalDumbCache = false; //< globally set cache "dumb" mode |
29 | QString HttpGet::m_globalUserAgent; //< globally set user agent for requests | ||
29 | 30 | ||
30 | HttpGet::HttpGet(QObject *parent) | 31 | HttpGet::HttpGet(QObject *parent) |
31 | : QObject(parent) | 32 | : QObject(parent) |
@@ -199,13 +200,19 @@ bool HttpGet::getFile(const QUrl &url) | |||
199 | m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex(); | 200 | m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex(); |
200 | m_path = QString(QUrl::toPercentEncoding(url.path(), "/")); | 201 | m_path = QString(QUrl::toPercentEncoding(url.path(), "/")); |
201 | 202 | ||
203 | // construct request header | ||
204 | m_header.setValue("Host", url.host()); | ||
205 | m_header.setValue("User-Agent", m_globalUserAgent); | ||
206 | m_header.setValue("Connection", "Keep-Alive"); | ||
207 | |||
202 | if(m_dumbCache || !m_usecache) { | 208 | if(m_dumbCache || !m_usecache) { |
203 | getFileFinish(); | 209 | getFileFinish(); |
204 | } | 210 | } |
205 | else { | 211 | else { |
206 | // request HTTP header | 212 | // schedule HTTP header request |
207 | connect(this, SIGNAL(headerFinished()), this, SLOT(getFileFinish())); | 213 | connect(this, SIGNAL(headerFinished()), this, SLOT(getFileFinish())); |
208 | headRequest = http.head(m_path + m_query); | 214 | m_header.setRequest("HEAD", m_path + m_query); |
215 | headRequest = http.request(m_header); | ||
209 | } | 216 | } |
210 | 217 | ||
211 | return true; | 218 | return true; |
@@ -262,15 +269,16 @@ void HttpGet::getFileFinish() | |||
262 | else { | 269 | else { |
263 | qDebug() << "[HTTP] cache DISABLED"; | 270 | qDebug() << "[HTTP] cache DISABLED"; |
264 | } | 271 | } |
265 | 272 | // schedule GET request | |
273 | m_header.setRequest("GET", m_path + m_query); | ||
266 | if(outputToBuffer) { | 274 | if(outputToBuffer) { |
267 | qDebug() << "[HTTP] downloading to buffer."; | 275 | qDebug() << "[HTTP] downloading to buffer."; |
268 | getRequest = http.get(m_path + m_query); | 276 | getRequest = http.request(m_header); |
269 | } | 277 | } |
270 | else { | 278 | else { |
271 | qDebug() << "[HTTP] downloading to file:" | 279 | qDebug() << "[HTTP] downloading to file:" |
272 | << qPrintable(outputFile->fileName()); | 280 | << qPrintable(outputFile->fileName()); |
273 | getRequest = http.get(m_path + m_query, outputFile); | 281 | getRequest = http.request(m_header, 0, outputFile); |
274 | } | 282 | } |
275 | qDebug() << "[HTTP] GET request scheduled, id:" << getRequest; | 283 | qDebug() << "[HTTP] GET request scheduled, id:" << getRequest; |
276 | 284 | ||