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. 11
      src/webui/httprequestparser.h
  4. 5
      src/webui/httpresponsegenerator.cpp
  5. 4
      src/webui/httpresponsegenerator.h

14
src/webui/httpconnection.cpp

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

4
src/webui/httprequestparser.cpp

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

11
src/webui/httprequestparser.h

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

5
src/webui/httpresponsegenerator.cpp

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

4
src/webui/httpresponsegenerator.h

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

Loading…
Cancel
Save