|
|
|
@ -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()) { |
|
|
|
|