mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 05:48:47 +03:00
Fix handling of simultaneous connections in Web UI.
May be related to issue #68.
This commit is contained in:
parent
51aae059e3
commit
32bfd8741f
2 changed files with 10 additions and 10 deletions
|
@ -78,21 +78,20 @@ void HttpConnection::handleDownloadFailure(const QString& url,
|
|||
}
|
||||
|
||||
void HttpConnection::read() {
|
||||
static QByteArray input;
|
||||
input.append(m_socket->readAll());
|
||||
m_receivedData.append(m_socket->readAll());
|
||||
|
||||
// Parse HTTP request header
|
||||
int header_end = input.indexOf("\r\n\r\n");
|
||||
int header_end = m_receivedData.indexOf("\r\n\r\n");
|
||||
if (header_end < 0) {
|
||||
qDebug() << "Partial request: \n" << input;
|
||||
qDebug() << "Partial request: \n" << m_receivedData;
|
||||
// Partial request waiting for the rest
|
||||
return;
|
||||
}
|
||||
QByteArray header = input.left(header_end);
|
||||
QByteArray header = m_receivedData.left(header_end);
|
||||
m_parser.writeHeader(header);
|
||||
if (m_parser.isError()) {
|
||||
qWarning() << Q_FUNC_INFO << "header parsing error";
|
||||
input.clear();
|
||||
m_receivedData.clear();
|
||||
m_generator.setStatusLine(400, "Bad Request");
|
||||
write();
|
||||
return;
|
||||
|
@ -101,12 +100,12 @@ void HttpConnection::read() {
|
|||
// Parse HTTP request message
|
||||
if (m_parser.header().hasContentLength()) {
|
||||
const int expected_length = m_parser.header().contentLength();
|
||||
QByteArray message = input.mid(header_end + 4, expected_length);
|
||||
QByteArray message = m_receivedData.mid(header_end + 4, expected_length);
|
||||
|
||||
if (expected_length > 10000000) {
|
||||
qWarning() << "Bad request: message too long";
|
||||
m_generator.setStatusLine(400, "Bad Request");
|
||||
input.clear();
|
||||
m_receivedData.clear();
|
||||
write();
|
||||
return;
|
||||
}
|
||||
|
@ -119,9 +118,9 @@ void HttpConnection::read() {
|
|||
|
||||
m_parser.writeMessage(message);
|
||||
|
||||
input = input.mid(header_end + 4 + expected_length);
|
||||
m_receivedData = m_receivedData.mid(header_end + 4 + expected_length);
|
||||
} else {
|
||||
input.clear();
|
||||
m_receivedData.clear();
|
||||
}
|
||||
|
||||
if (m_parser.isError()) {
|
||||
|
|
|
@ -88,6 +88,7 @@ private:
|
|||
HttpServer *m_httpserver;
|
||||
HttpRequestParser m_parser;
|
||||
HttpResponseGenerator m_generator;
|
||||
QByteArray m_receivedData;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue