1
0
Fork 0
forked from len0rd/rockbox

RFC2616 requires requests made to proxies to use the absoluteURI form while HTTP/1.1 clients shall only create it when sending a request to a proxy. Fixes proxy support not working correctly (most noticably on theme installation).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20992 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Riebeling 2009-05-19 22:46:57 +00:00
parent 2755b93ba8
commit 132176e120
2 changed files with 22 additions and 6 deletions

View file

@ -39,6 +39,7 @@ HttpGet::HttpGet(QObject *parent)
// if a request is cancelled before a reponse is available return some
// hint about this in the http response instead of nonsense.
m_response = -1;
m_useproxy = false;
// default to global proxy / cache if not empty.
// proxy is automatically enabled, disable it by setting an empty proxy
@ -130,17 +131,24 @@ QHttp::Error HttpGet::error()
void HttpGet::setProxy(const QUrl &proxy)
{
m_proxy = proxy;
http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password());
m_useproxy = true;
http.setProxy(m_proxy.host(), m_proxy.port(),
m_proxy.userName(), m_proxy.password());
}
void HttpGet::setProxy(bool enable)
{
if(enable)
http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password());
else
if(enable) {
m_useproxy = true;
http.setProxy(m_proxy.host(), m_proxy.port(),
m_proxy.userName(), m_proxy.password());
}
else {
m_useproxy = false;
http.setProxy("", 0);
}
}
void HttpGet::setFile(QFile *file)
@ -203,7 +211,12 @@ bool HttpGet::getFile(const QUrl &url)
// create hash used for caching
m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex();
m_path = QString(QUrl::toPercentEncoding(url.path(), "/"));
// RFC2616: the absoluteURI form must get used when the request is being
// sent to a proxy.
m_path.clear();
if(m_useproxy)
m_path = url.scheme() + "://" + url.host();
m_path += QString(QUrl::toPercentEncoding(url.path(), "/"));
// construct request header
m_header.setValue("Host", url.host());
@ -239,7 +252,8 @@ void HttpGet::getFileFinish()
getRequest = -1;
QFile c(m_cachefile);
if(!outputToBuffer) {
qDebug() << "[HTTP] Cache: copying file to output" << outputFile->fileName();
qDebug() << "[HTTP] Cache: copying file to output"
<< outputFile->fileName();
c.open(QIODevice::ReadOnly);
outputFile->open(QIODevice::ReadWrite);
outputFile->write(c.readAll());
@ -272,6 +286,7 @@ void HttpGet::getFileFinish()
qDebug() << "[HTTP] cache DISABLED";
}
// schedule GET request
m_header.setRequest("GET", m_path + m_query);
if(outputToBuffer) {
qDebug() << "[HTTP] downloading to buffer.";

View file

@ -91,6 +91,7 @@ class HttpGet : public QObject
QString m_cachefile; // cached filename
bool m_cached;
QUrl m_proxy;
bool m_useproxy;
QDateTime m_serverTimestamp; //< timestamp of file on server
QString m_query; //< constructed query to pass http getter
QString m_path; //< constructed path to pass http getter