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:
parent
2755b93ba8
commit
132176e120
2 changed files with 22 additions and 6 deletions
|
@ -39,6 +39,7 @@ HttpGet::HttpGet(QObject *parent)
|
||||||
// if a request is cancelled before a reponse is available return some
|
// if a request is cancelled before a reponse is available return some
|
||||||
// hint about this in the http response instead of nonsense.
|
// hint about this in the http response instead of nonsense.
|
||||||
m_response = -1;
|
m_response = -1;
|
||||||
|
m_useproxy = false;
|
||||||
|
|
||||||
// default to global proxy / cache if not empty.
|
// default to global proxy / cache if not empty.
|
||||||
// proxy is automatically enabled, disable it by setting an empty proxy
|
// proxy is automatically enabled, disable it by setting an empty proxy
|
||||||
|
@ -130,16 +131,23 @@ QHttp::Error HttpGet::error()
|
||||||
void HttpGet::setProxy(const QUrl &proxy)
|
void HttpGet::setProxy(const QUrl &proxy)
|
||||||
{
|
{
|
||||||
m_proxy = 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)
|
void HttpGet::setProxy(bool enable)
|
||||||
{
|
{
|
||||||
if(enable)
|
if(enable) {
|
||||||
http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password());
|
m_useproxy = true;
|
||||||
else
|
http.setProxy(m_proxy.host(), m_proxy.port(),
|
||||||
|
m_proxy.userName(), m_proxy.password());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_useproxy = false;
|
||||||
http.setProxy("", 0);
|
http.setProxy("", 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,7 +211,12 @@ bool HttpGet::getFile(const QUrl &url)
|
||||||
|
|
||||||
// create hash used for caching
|
// create hash used for caching
|
||||||
m_hash = QCryptographicHash::hash(url.toEncoded(), QCryptographicHash::Md5).toHex();
|
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
|
// construct request header
|
||||||
m_header.setValue("Host", url.host());
|
m_header.setValue("Host", url.host());
|
||||||
|
@ -239,7 +252,8 @@ void HttpGet::getFileFinish()
|
||||||
getRequest = -1;
|
getRequest = -1;
|
||||||
QFile c(m_cachefile);
|
QFile c(m_cachefile);
|
||||||
if(!outputToBuffer) {
|
if(!outputToBuffer) {
|
||||||
qDebug() << "[HTTP] Cache: copying file to output" << outputFile->fileName();
|
qDebug() << "[HTTP] Cache: copying file to output"
|
||||||
|
<< outputFile->fileName();
|
||||||
c.open(QIODevice::ReadOnly);
|
c.open(QIODevice::ReadOnly);
|
||||||
outputFile->open(QIODevice::ReadWrite);
|
outputFile->open(QIODevice::ReadWrite);
|
||||||
outputFile->write(c.readAll());
|
outputFile->write(c.readAll());
|
||||||
|
@ -272,6 +286,7 @@ void HttpGet::getFileFinish()
|
||||||
qDebug() << "[HTTP] cache DISABLED";
|
qDebug() << "[HTTP] cache DISABLED";
|
||||||
}
|
}
|
||||||
// schedule GET request
|
// schedule GET request
|
||||||
|
|
||||||
m_header.setRequest("GET", m_path + m_query);
|
m_header.setRequest("GET", m_path + m_query);
|
||||||
if(outputToBuffer) {
|
if(outputToBuffer) {
|
||||||
qDebug() << "[HTTP] downloading to buffer.";
|
qDebug() << "[HTTP] downloading to buffer.";
|
||||||
|
|
|
@ -91,6 +91,7 @@ class HttpGet : public QObject
|
||||||
QString m_cachefile; // cached filename
|
QString m_cachefile; // cached filename
|
||||||
bool m_cached;
|
bool m_cached;
|
||||||
QUrl m_proxy;
|
QUrl m_proxy;
|
||||||
|
bool m_useproxy;
|
||||||
QDateTime m_serverTimestamp; //< timestamp of file on server
|
QDateTime m_serverTimestamp; //< timestamp of file on server
|
||||||
QString m_query; //< constructed query to pass http getter
|
QString m_query; //< constructed query to pass http getter
|
||||||
QString m_path; //< constructed path to pass http getter
|
QString m_path; //< constructed path to pass http getter
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue