From 32bfd8741f90fe7daa1da7fb5638b4f28d7c9a98 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 29 Sep 2012 14:11:07 +0300 Subject: [PATCH] Fix handling of simultaneous connections in Web UI. May be related to issue #68. --- src/webui/httpconnection.cpp | 19 +++++++++---------- src/webui/httpconnection.h | 1 + 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/webui/httpconnection.cpp b/src/webui/httpconnection.cpp index 68b0b3257..097ebe85d 100644 --- a/src/webui/httpconnection.cpp +++ b/src/webui/httpconnection.cpp @@ -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()) { diff --git a/src/webui/httpconnection.h b/src/webui/httpconnection.h index 970768617..1af5fcc04 100644 --- a/src/webui/httpconnection.h +++ b/src/webui/httpconnection.h @@ -88,6 +88,7 @@ private: HttpServer *m_httpserver; HttpRequestParser m_parser; HttpResponseGenerator m_generator; + QByteArray m_receivedData; }; #endif