summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-08-30 20:51:50 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-08-30 20:51:50 +0000
commit90f92b216be2e1e413b61afb59fdfd3cac1b798e (patch)
tree81a44b77d74b767aee9ca4a646ff6cffa85c736a
parent76a3959ac2b5730368e966e6d23f79b847f33e9f (diff)
downloadrockbox-90f92b216be2e1e413b61afb59fdfd3cac1b798e.tar.gz
rockbox-90f92b216be2e1e413b61afb59fdfd3cac1b798e.zip
Add setting the User-Agent for http requests to HttpGet class. Make rbutil set its own user agent string.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18366 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/rbutilqt/httpget.cpp18
-rw-r--r--rbutil/rbutilqt/httpget.h11
-rw-r--r--rbutil/rbutilqt/rbutilqt.cpp5
-rw-r--r--rbutil/rbutilqt/version.h7
4 files changed, 29 insertions, 12 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 @@
26QDir HttpGet::m_globalCache; //< global cach path value for new objects 26QDir HttpGet::m_globalCache; //< global cach path value for new objects
27QUrl HttpGet::m_globalProxy; //< global proxy value for new objects 27QUrl HttpGet::m_globalProxy; //< global proxy value for new objects
28bool HttpGet::m_globalDumbCache = false; //< globally set cache "dumb" mode 28bool HttpGet::m_globalDumbCache = false; //< globally set cache "dumb" mode
29QString HttpGet::m_globalUserAgent; //< globally set user agent for requests
29 30
30HttpGet::HttpGet(QObject *parent) 31HttpGet::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
diff --git a/rbutil/rbutilqt/httpget.h b/rbutil/rbutilqt/httpget.h
index 72a76e43c1..ba4cbc821e 100644
--- a/rbutil/rbutilqt/httpget.h
+++ b/rbutil/rbutilqt/httpget.h
@@ -57,6 +57,8 @@ class HttpGet : public QObject
57 { m_globalProxy = p; } 57 { m_globalProxy = p; }
58 static void setGlobalDumbCache(bool b) //< set "dumb" (ignore server status) caching mode 58 static void setGlobalDumbCache(bool b) //< set "dumb" (ignore server status) caching mode
59 { m_globalDumbCache = b; } 59 { m_globalDumbCache = b; }
60 static void setGlobalUserAgent(QString u) //< set global user agent string
61 { m_globalUserAgent = u; }
60 62
61 public slots: 63 public slots:
62 void abort(void); 64 void abort(void);
@@ -89,14 +91,17 @@ class HttpGet : public QObject
89 QString m_cachefile; // cached filename 91 QString m_cachefile; // cached filename
90 bool m_cached; 92 bool m_cached;
91 QUrl m_proxy; 93 QUrl m_proxy;
92 static QDir m_globalCache; //< global cache path value
93 static QUrl m_globalProxy; //< global proxy value
94 static bool m_globalDumbCache; //< cache "dumb" mode global setting
95 QDateTime m_serverTimestamp; //< timestamp of file on server 94 QDateTime m_serverTimestamp; //< timestamp of file on server
96 QString m_query; //< constructed query to pass http getter 95 QString m_query; //< constructed query to pass http getter
97 QString m_path; //< constructed path to pass http getter 96 QString m_path; //< constructed path to pass http getter
98 QString m_hash; //< caching hash 97 QString m_hash; //< caching hash
99 bool m_dumbCache; //< true if caching should ignore the server header 98 bool m_dumbCache; //< true if caching should ignore the server header
99 QHttpRequestHeader m_header;
100
101 static QDir m_globalCache; //< global cache path value
102 static QUrl m_globalProxy; //< global proxy value
103 static bool m_globalDumbCache; //< cache "dumb" mode global setting
104 static QString m_globalUserAgent; //< global user agent string
100}; 105};
101 106
102#endif 107#endif
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp
index 8921eadb9a..e64a1a6eb3 100644
--- a/rbutil/rbutilqt/rbutilqt.cpp
+++ b/rbutil/rbutilqt/rbutilqt.cpp
@@ -57,7 +57,8 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
57 57
58 settings = new RbSettings(); 58 settings = new RbSettings();
59 settings->open(); 59 settings->open();
60 60 HttpGet::setGlobalUserAgent("rbutil/"VERSION);
61
61 m_gotInfo = false; 62 m_gotInfo = false;
62 63
63 // manual tab 64 // manual tab
@@ -241,7 +242,7 @@ void RbUtilQt::about()
241 QString rline = r.readAll(); 242 QString rline = r.readAll();
242 about.browserCredits->insertPlainText(rline); 243 about.browserCredits->insertPlainText(rline);
243 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor); 244 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
244 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(VERSION); 245 QString title = QString("<b>The Rockbox Utility</b><br/>Version %1").arg(FULLVERSION);
245 about.labelTitle->setText(title); 246 about.labelTitle->setText(title);
246 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>"); 247 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
247 248
diff --git a/rbutil/rbutilqt/version.h b/rbutil/rbutilqt/version.h
index c0ba2bf848..8027b574f9 100644
--- a/rbutil/rbutilqt/version.h
+++ b/rbutil/rbutilqt/version.h
@@ -19,9 +19,12 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#define VERSION "SVN $Revision$ (m1.0.6), built "__DATE__" "__TIME__
23
24// PUREVERSION is needed to be able to just compare versions. It does not 22// PUREVERSION is needed to be able to just compare versions. It does not
25// contain a build timestamp because it needs to be the same in different 23// contain a build timestamp because it needs to be the same in different
26// files 24// files
25// VERSION is the plain version number, used for http User-Agent string.
26#define VERSION "m1.0.6"
27#define PUREVERSION "SVN $Revision$" 27#define PUREVERSION "SVN $Revision$"
28
29#define FULLVERSION PUREVERSION" ("VERSION"), built "__DATE__" "__TIME__
30