Browse Source

HTTP request handling clean up and optimization

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
8986d87ef3
  1. 14
      src/webui/httpconnection.cpp
  2. 4
      src/webui/httprequestparser.cpp
  3. 13
      src/webui/httprequestparser.h
  4. 7
      src/webui/httpresponsegenerator.cpp
  5. 4
      src/webui/httpresponsegenerator.h

14
src/webui/httpconnection.cpp

@ -220,7 +220,7 @@ void HttpConnection::respond() { @@ -220,7 +220,7 @@ void HttpConnection::respond() {
qDebug("Returning favicon");
QFile favicon(":/Icons/skin/qbittorrent16.png");
if (favicon.open(QIODevice::ReadOnly)) {
QByteArray data = favicon.readAll();
const QByteArray data = favicon.readAll();
favicon.close();
m_generator.setStatusLine(200, "OK");
m_generator.setContentTypeByExt("png");
@ -474,9 +474,9 @@ void HttpConnection::respondCommand(const QString& command) { @@ -474,9 +474,9 @@ void HttpConnection::respondCommand(const QString& command) {
m_generator.setStatusLine(200, "OK");
m_generator.setContentTypeByExt("html");
#if LIBTORRENT_VERSION_MINOR > 15
m_generator.setMessage(QString::number(QBtSession::instance()->getSession()->settings().upload_rate_limit));
m_generator.setMessage(QByteArray::number(QBtSession::instance()->getSession()->settings().upload_rate_limit));
#else
m_generator.setMessage(QString::number(QBtSession::instance()->getSession()->upload_rate_limit()));
m_generator.setMessage(QByteArray::number(QBtSession::instance()->getSession()->upload_rate_limit()));
#endif
write();
return;
@ -485,9 +485,9 @@ void HttpConnection::respondCommand(const QString& command) { @@ -485,9 +485,9 @@ void HttpConnection::respondCommand(const QString& command) {
m_generator.setStatusLine(200, "OK");
m_generator.setContentTypeByExt("html");
#if LIBTORRENT_VERSION_MINOR > 15
m_generator.setMessage(QString::number(QBtSession::instance()->getSession()->settings().download_rate_limit));
m_generator.setMessage(QByteArray::number(QBtSession::instance()->getSession()->settings().download_rate_limit));
#else
m_generator.setMessage(QString::number(QBtSession::instance()->getSession()->download_rate_limit()));
m_generator.setMessage(QByteArray::number(QBtSession::instance()->getSession()->download_rate_limit()));
#endif
write();
return;
@ -498,7 +498,7 @@ void HttpConnection::respondCommand(const QString& command) { @@ -498,7 +498,7 @@ void HttpConnection::respondCommand(const QString& command) {
if (h.is_valid()) {
m_generator.setStatusLine(200, "OK");
m_generator.setContentTypeByExt("html");
m_generator.setMessage(QString::number(h.upload_limit()));
m_generator.setMessage(QByteArray::number(h.upload_limit()));
write();
}
return;
@ -509,7 +509,7 @@ void HttpConnection::respondCommand(const QString& command) { @@ -509,7 +509,7 @@ void HttpConnection::respondCommand(const QString& command) {
if (h.is_valid()) {
m_generator.setStatusLine(200, "OK");
m_generator.setContentTypeByExt("html");
m_generator.setMessage(QString::number(h.download_limit()));
m_generator.setMessage(QByteArray::number(h.download_limit()));
write();
}
return;

4
src/webui/httprequestparser.cpp

@ -45,11 +45,11 @@ bool HttpRequestParser::isError() const { @@ -45,11 +45,11 @@ bool HttpRequestParser::isError() const {
return m_error;
}
QString HttpRequestParser::url() const {
const QString& HttpRequestParser::url() const {
return m_path;
}
QByteArray HttpRequestParser::message() const {
const QByteArray& HttpRequestParser::message() const {
return m_data;
}

13
src/webui/httprequestparser.h

@ -32,7 +32,8 @@ @@ -32,7 +32,8 @@
#ifndef HTTPREQUESTPARSER_H
#define HTTPREQUESTPARSER_H
#include<QHttpRequestHeader>
#include <QHttpRequestHeader>
#include <QHash>
class HttpRequestParser {
@ -40,22 +41,22 @@ public: @@ -40,22 +41,22 @@ public:
HttpRequestParser();
~HttpRequestParser();
bool isError() const;
QString url() const;
QByteArray message() const;
const QString& url() const;
const QByteArray& message() const;
QString get(const QString& key) const;
QString post(const QString& key) const;
const QByteArray& torrent() const;
void writeHeader(const QByteArray& ba);
void writeMessage(const QByteArray& ba);
inline QHttpRequestHeader& header() { return m_header; }
inline const QHttpRequestHeader& header() const { return m_header; }
private:
QHttpRequestHeader m_header;
bool m_error;
QByteArray m_data;
QString m_path;
QMap<QString, QString> m_postMap;
QMap<QString, QString> m_getMap;
QHash<QString, QString> m_postMap;
QHash<QString, QString> m_getMap;
QByteArray m_torrentContent;
};

7
src/webui/httpresponsegenerator.cpp

@ -33,11 +33,12 @@ @@ -33,11 +33,12 @@
void HttpResponseGenerator::setMessage(const QByteArray& message)
{
HttpResponseGenerator::message = message;
setContentLength(message.size());
m_message = message;
setContentLength(message.size());
}
void HttpResponseGenerator::setMessage(const QString& message) {
void HttpResponseGenerator::setMessage(const QString& message)
{
setMessage(message.toUtf8());
}

4
src/webui/httpresponsegenerator.h

@ -42,11 +42,11 @@ class HttpResponseGenerator : public QHttpResponseHeader @@ -42,11 +42,11 @@ class HttpResponseGenerator : public QHttpResponseHeader
void setMessage(const QString& message);
void setContentTypeByExt(const QString& ext);
inline QByteArray toByteArray() const {
return QHttpResponseHeader::toString().toUtf8() + message;
return QHttpResponseHeader::toString().toUtf8() + m_message;
}
private:
QByteArray message;
QByteArray m_message;
};

Loading…
Cancel
Save