Browse Source

Fix handling of simultaneous connections in Web UI.

May be related to issue #68.
adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
32bfd8741f
  1. 19
      src/webui/httpconnection.cpp
  2. 1
      src/webui/httpconnection.h

19
src/webui/httpconnection.cpp

@ -78,21 +78,20 @@ void HttpConnection::handleDownloadFailure(const QString& url, @@ -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() { @@ -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() { @@ -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()) {

1
src/webui/httpconnection.h

@ -88,6 +88,7 @@ private: @@ -88,6 +88,7 @@ private:
HttpServer *m_httpserver;
HttpRequestParser m_parser;
HttpResponseGenerator m_generator;
QByteArray m_receivedData;
};
#endif

Loading…
Cancel
Save