mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-09 04:08:16 +08:00
Use the new Http classes.
This commit is contained in:
parent
6096506bd6
commit
e8c14f3507
@ -28,7 +28,6 @@
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#include <QHttpRequestHeader>
|
||||
#include <QTcpSocket>
|
||||
#include <QUrl>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
@ -38,6 +37,8 @@
|
||||
#include <libtorrent/bencode.hpp>
|
||||
#include <libtorrent/entry.hpp>
|
||||
|
||||
#include "httprequestheader.h"
|
||||
#include "httpresponseheader.h"
|
||||
#include "qtracker.h"
|
||||
#include "preferences.h"
|
||||
|
||||
@ -90,7 +91,7 @@ void QTracker::readRequest()
|
||||
QTcpSocket *socket = static_cast<QTcpSocket*>(sender());
|
||||
QByteArray input = socket->readAll();
|
||||
//qDebug("QTracker: Raw request:\n%s", input.data());
|
||||
QHttpRequestHeader http_request(input);
|
||||
HttpRequestHeader http_request(input);
|
||||
if (!http_request.isValid()) {
|
||||
qDebug("QTracker: Invalid HTTP Request:\n %s", qPrintable(http_request.toString()));
|
||||
respondInvalidRequest(socket, 100, "Invalid request type");
|
||||
@ -129,7 +130,7 @@ void QTracker::readRequest()
|
||||
|
||||
void QTracker::respondInvalidRequest(QTcpSocket *socket, int code, QString msg)
|
||||
{
|
||||
QHttpResponseHeader response;
|
||||
HttpResponseHeader response;
|
||||
response.setStatusLine(code, msg);
|
||||
socket->write(response.toString().toLocal8Bit());
|
||||
socket->disconnectFromHost();
|
||||
@ -246,7 +247,7 @@ void QTracker::ReplyWithPeerList(QTcpSocket *socket, const TrackerAnnounceReques
|
||||
QByteArray reply(&buf[0], buf.size());
|
||||
qDebug("QTracker: reply with the following bencoded data:\n %s", reply.constData());
|
||||
// HTTP reply
|
||||
QHttpResponseHeader response;
|
||||
HttpResponseHeader response;
|
||||
response.setStatusLine(200, "OK");
|
||||
socket->write(response.toString().toLocal8Bit() + reply);
|
||||
socket->disconnectFromHost();
|
||||
|
@ -32,7 +32,6 @@
|
||||
#define QTRACKER_H
|
||||
|
||||
#include <QTcpServer>
|
||||
#include <QHttpResponseHeader>
|
||||
#include <QHash>
|
||||
|
||||
#include "trackerannouncerequest.h"
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
#include "httpconnection.h"
|
||||
#include "httpserver.h"
|
||||
#include "httprequestheader.h"
|
||||
#include "httpresponseheader.h"
|
||||
#include "preferences.h"
|
||||
#include "btjson.h"
|
||||
#include "prefjson.h"
|
||||
@ -42,8 +44,6 @@
|
||||
#include <QTcpSocket>
|
||||
#include <QDateTime>
|
||||
#include <QStringList>
|
||||
#include <QHttpRequestHeader>
|
||||
#include <QHttpResponseHeader>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QRegExp>
|
||||
|
@ -71,7 +71,7 @@ const QList<QByteArray>& HttpRequestParser::torrents() const {
|
||||
void HttpRequestParser::writeHeader(const QByteArray& ba) {
|
||||
m_error = false;
|
||||
// Parse header
|
||||
m_header = QHttpRequestHeader(ba);
|
||||
m_header = HttpRequestHeader(ba);
|
||||
QUrl url = QUrl::fromEncoded(m_header.path().toLatin1());
|
||||
m_path = url.path();
|
||||
|
||||
|
@ -32,8 +32,8 @@
|
||||
#ifndef HTTPREQUESTPARSER_H
|
||||
#define HTTPREQUESTPARSER_H
|
||||
|
||||
#include <QHttpRequestHeader>
|
||||
#include <QHash>
|
||||
#include "httprequestheader.h"
|
||||
|
||||
class HttpRequestParser {
|
||||
|
||||
@ -49,10 +49,10 @@ public:
|
||||
void writeHeader(const QByteArray& ba);
|
||||
void writeMessage(const QByteArray& ba);
|
||||
bool acceptsEncoding();
|
||||
inline const QHttpRequestHeader& header() const { return m_header; }
|
||||
inline const HttpRequestHeader& header() const { return m_header; }
|
||||
|
||||
private:
|
||||
QHttpRequestHeader m_header;
|
||||
HttpRequestHeader m_header;
|
||||
bool m_error;
|
||||
QByteArray m_data;
|
||||
QString m_path;
|
||||
|
@ -136,5 +136,5 @@ QByteArray HttpResponseGenerator::toByteArray() {
|
||||
}
|
||||
|
||||
setContentLength(m_message.size());
|
||||
return QHttpResponseHeader::toString().toUtf8() + m_message;
|
||||
return HttpResponseHeader::toString().toUtf8() + m_message;
|
||||
}
|
||||
|
@ -32,9 +32,9 @@
|
||||
#ifndef HTTPRESPONSEGENERATOR_H
|
||||
#define HTTPRESPONSEGENERATOR_H
|
||||
|
||||
#include<QHttpResponseHeader>
|
||||
#include "httpresponseheader.h"
|
||||
|
||||
class HttpResponseGenerator : public QHttpResponseHeader
|
||||
class HttpResponseGenerator : public HttpResponseHeader
|
||||
{
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user