summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/base')
-rw-r--r--rbutil/rbutilqt/base/httpget.cpp27
-rw-r--r--rbutil/rbutilqt/base/httpget.h1
2 files changed, 22 insertions, 6 deletions
diff --git a/rbutil/rbutilqt/base/httpget.cpp b/rbutil/rbutilqt/base/httpget.cpp
index 23249b2765..dab93d1b19 100644
--- a/rbutil/rbutilqt/base/httpget.cpp
+++ b/rbutil/rbutilqt/base/httpget.cpp
@@ -39,6 +39,7 @@ HttpGet::HttpGet(QObject *parent)
39 // if a request is cancelled before a reponse is available return some 39 // if a request is cancelled before a reponse is available return some
40 // hint about this in the http response instead of nonsense. 40 // hint about this in the http response instead of nonsense.
41 m_response = -1; 41 m_response = -1;
42 m_useproxy = false;
42 43
43 // default to global proxy / cache if not empty. 44 // default to global proxy / cache if not empty.
44 // proxy is automatically enabled, disable it by setting an empty proxy 45 // proxy is automatically enabled, disable it by setting an empty proxy
@@ -130,16 +131,23 @@ QHttp::Error HttpGet::error()
130void HttpGet::setProxy(const QUrl &proxy) 131void HttpGet::setProxy(const QUrl &proxy)
131{ 132{
132 m_proxy = proxy; 133 m_proxy = proxy;
133 http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password()); 134 m_useproxy = true;
135 http.setProxy(m_proxy.host(), m_proxy.port(),
136 m_proxy.userName(), m_proxy.password());
134} 137}
135 138
136 139
137void HttpGet::setProxy(bool enable) 140void HttpGet::setProxy(bool enable)
138{ 141{
139 if(enable) 142 if(enable) {
140 http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password()); 143 m_useproxy = true;
141 else 144 http.setProxy(m_proxy.host(), m_proxy.port(),
145 m_proxy.userName(), m_proxy.password());
146 }
147 else {
148 m_useproxy = false;
142 http.setProxy("", 0); 149 http.setProxy("", 0);
150 }
143} 151}
144 152
145 153
@@ -203,7 +211,12 @@ bool HttpGet::getFile(const QUrl &url)
203 211
204 // create hash used for caching 212 // create hash used for caching
205 m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex(); 213 m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex();
206 m_path = QString(QUrl::toPercentEncoding(url.path(), "/")); 214 // RFC2616: the absoluteURI form must get used when the request is being
215 // sent to a proxy.
216 m_path.clear();
217 if(m_useproxy)
218 m_path = url.scheme() + "://" + url.host();
219 m_path += QString(QUrl::toPercentEncoding(url.path(), "/"));
207 220
208 // construct request header 221 // construct request header
209 m_header.setValue("Host", url.host()); 222 m_header.setValue("Host", url.host());
@@ -239,7 +252,8 @@ void HttpGet::getFileFinish()
239 getRequest = -1; 252 getRequest = -1;
240 QFile c(m_cachefile); 253 QFile c(m_cachefile);
241 if(!outputToBuffer) { 254 if(!outputToBuffer) {
242 qDebug() << "[HTTP] Cache: copying file to output" << outputFile->fileName(); 255 qDebug() << "[HTTP] Cache: copying file to output"
256 << outputFile->fileName();
243 c.open(QIODevice::ReadOnly); 257 c.open(QIODevice::ReadOnly);
244 outputFile->open(QIODevice::ReadWrite); 258 outputFile->open(QIODevice::ReadWrite);
245 outputFile->write(c.readAll()); 259 outputFile->write(c.readAll());
@@ -272,6 +286,7 @@ void HttpGet::getFileFinish()
272 qDebug() << "[HTTP] cache DISABLED"; 286 qDebug() << "[HTTP] cache DISABLED";
273 } 287 }
274 // schedule GET request 288 // schedule GET request
289
275 m_header.setRequest("GET", m_path + m_query); 290 m_header.setRequest("GET", m_path + m_query);
276 if(outputToBuffer) { 291 if(outputToBuffer) {
277 qDebug() << "[HTTP] downloading to buffer."; 292 qDebug() << "[HTTP] downloading to buffer.";
diff --git a/rbutil/rbutilqt/base/httpget.h b/rbutil/rbutilqt/base/httpget.h
index 4bf1987998..8dcf427de4 100644
--- a/rbutil/rbutilqt/base/httpget.h
+++ b/rbutil/rbutilqt/base/httpget.h
@@ -91,6 +91,7 @@ class HttpGet : public QObject
91 QString m_cachefile; // cached filename 91 QString m_cachefile; // cached filename
92 bool m_cached; 92 bool m_cached;
93 QUrl m_proxy; 93 QUrl m_proxy;
94 bool m_useproxy;
94 QDateTime m_serverTimestamp; //< timestamp of file on server 95 QDateTime m_serverTimestamp; //< timestamp of file on server
95 QString m_query; //< constructed query to pass http getter 96 QString m_query; //< constructed query to pass http getter
96 QString m_path; //< constructed path to pass http getter 97 QString m_path; //< constructed path to pass http getter