HTTP server: prefix log messages with method signature

This commit is contained in:
f4exb 2018-02-11 21:45:44 +01:00
parent b56a4c7a57
commit 132e84b2b6
4 changed files with 37 additions and 37 deletions

View File

@ -112,7 +112,7 @@ void HttpConnectionHandlerPool::loadSslConfig()
if (!sslKeyFileName.isEmpty() && !sslCertFileName.isEmpty()) if (!sslKeyFileName.isEmpty() && !sslCertFileName.isEmpty())
{ {
#ifdef QT_NO_OPENSSL #ifdef QT_NO_OPENSSL
qWarning("HttpConnectionHandlerPool: SSL is not supported"); qWarning("HttpConnectionHandlerPool::loadSslConfig: SSL is not supported");
#else #else
// Convert relative fileNames to absolute, based on the directory of the config file. // Convert relative fileNames to absolute, based on the directory of the config file.
QFileInfo configFile(settings->fileName()); QFileInfo configFile(settings->fileName());

View File

@ -88,7 +88,7 @@ HttpCookie::HttpCookie(const QByteArray source)
} }
else else
{ {
qWarning("HttpCookie: Ignoring unknown %s=%s",name.data(),value.data()); qWarning("HttpCookie::HttpCookie: Ignoring unknown %s=%s",name.data(),value.data());
} }
} }
} }

View File

@ -40,7 +40,7 @@ HttpRequest::HttpRequest(const HttpListenerSettings* settings) :
void HttpRequest::readRequest(QTcpSocket* socket) void HttpRequest::readRequest(QTcpSocket* socket)
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: read request"); qDebug("HttpRequest::readRequest: read request");
#endif #endif
int toRead=maxSize-currentSize+1; // allow one byte more to be able to detect overflow int toRead=maxSize-currentSize+1; // allow one byte more to be able to detect overflow
lineBuffer.append(socket->readLine(toRead)); lineBuffer.append(socket->readLine(toRead));
@ -48,7 +48,7 @@ void HttpRequest::readRequest(QTcpSocket* socket)
if (!lineBuffer.contains('\r') && !lineBuffer.contains('\n')) if (!lineBuffer.contains('\r') && !lineBuffer.contains('\n'))
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: collecting more parts until line break"); qDebug("HttpRequest::readRequest: collecting more parts until line break");
#endif #endif
return; return;
} }
@ -59,7 +59,7 @@ void HttpRequest::readRequest(QTcpSocket* socket)
QList<QByteArray> list=newData.split(' '); QList<QByteArray> list=newData.split(' ');
if (list.count()!=3 || !list.at(2).contains("HTTP")) if (list.count()!=3 || !list.at(2).contains("HTTP"))
{ {
qWarning("HttpRequest: received broken HTTP request, invalid first line"); qWarning("HttpRequest::readRequest: received broken HTTP request, invalid first line");
status=abort; status=abort;
} }
else { else {
@ -75,7 +75,7 @@ void HttpRequest::readRequest(QTcpSocket* socket)
void HttpRequest::readHeader(QTcpSocket* socket) void HttpRequest::readHeader(QTcpSocket* socket)
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: read header"); qDebug("HttpRequest::readHeader");
#endif #endif
int toRead=maxSize-currentSize+1; // allow one byte more to be able to detect overflow int toRead=maxSize-currentSize+1; // allow one byte more to be able to detect overflow
lineBuffer.append(socket->readLine(toRead)); lineBuffer.append(socket->readLine(toRead));
@ -83,7 +83,7 @@ void HttpRequest::readHeader(QTcpSocket* socket)
if (!lineBuffer.contains('\r') && !lineBuffer.contains('\n')) if (!lineBuffer.contains('\r') && !lineBuffer.contains('\n'))
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: collecting more parts until line break"); qDebug("HttpRequest::readHeader: collecting more parts until line break");
#endif #endif
return; return;
} }
@ -97,14 +97,14 @@ void HttpRequest::readHeader(QTcpSocket* socket)
QByteArray value=newData.mid(colon+1).trimmed(); QByteArray value=newData.mid(colon+1).trimmed();
headers.insert(currentHeader,value); headers.insert(currentHeader,value);
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: received header %s: %s",currentHeader.data(),value.data()); qDebug("HttpRequest::readHeader: received header %s: %s",currentHeader.data(),value.data());
#endif #endif
} }
else if (!newData.isEmpty()) else if (!newData.isEmpty())
{ {
// received another line - belongs to the previous header // received another line - belongs to the previous header
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: read additional line of header"); qDebug("HttpRequest::readHeader: read additional line of header");
#endif #endif
// Received additional line of previous header // Received additional line of previous header
if (headers.contains(currentHeader)) { if (headers.contains(currentHeader)) {
@ -115,7 +115,7 @@ void HttpRequest::readHeader(QTcpSocket* socket)
{ {
// received an empty line - end of headers reached // received an empty line - end of headers reached
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: headers completed"); qDebug("HttpRequest::readHeader: headers completed");
#endif #endif
// Empty line received, that means all headers have been received // Empty line received, that means all headers have been received
// Check for multipart/form-data // Check for multipart/form-data
@ -139,23 +139,23 @@ void HttpRequest::readHeader(QTcpSocket* socket)
if (expectedBodySize==0) if (expectedBodySize==0)
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: expect no body"); qDebug("HttpRequest::readHeader: expect no body");
#endif #endif
status=complete; status=complete;
} }
else if (boundary.isEmpty() && expectedBodySize+currentSize>maxSize) else if (boundary.isEmpty() && expectedBodySize+currentSize>maxSize)
{ {
qWarning("HttpRequest: expected body is too large"); qWarning("HttpRequest::readHeader: expected body is too large");
status=abort; status=abort;
} }
else if (!boundary.isEmpty() && expectedBodySize>maxMultiPartSize) else if (!boundary.isEmpty() && expectedBodySize>maxMultiPartSize)
{ {
qWarning("HttpRequest: expected multipart body is too large"); qWarning("HttpRequest::readHeader: expected multipart body is too large");
status=abort; status=abort;
} }
else { else {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: expect %i bytes body",expectedBodySize); qDebug("HttpRequest::readHeader: expect %i bytes body",expectedBodySize);
#endif #endif
status=waitForBody; status=waitForBody;
} }
@ -169,7 +169,7 @@ void HttpRequest::readBody(QTcpSocket* socket)
{ {
// normal body, no multipart // normal body, no multipart
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: receive body"); qDebug("HttpRequest::readBody: receive body");
#endif #endif
int toRead=expectedBodySize-bodyData.size(); int toRead=expectedBodySize-bodyData.size();
QByteArray newData=socket->read(toRead); QByteArray newData=socket->read(toRead);
@ -184,7 +184,7 @@ void HttpRequest::readBody(QTcpSocket* socket)
{ {
// multipart body, store into temp file // multipart body, store into temp file
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: receiving multipart body"); qDebug("HttpRequest::readBody: receiving multipart body");
#endif #endif
// Create an object for the temporary file, if not already present // Create an object for the temporary file, if not already present
if (tempFile == NULL) if (tempFile == NULL)
@ -205,18 +205,18 @@ void HttpRequest::readBody(QTcpSocket* socket)
fileSize+=tempFile->write(socket->read(toRead)); fileSize+=tempFile->write(socket->read(toRead));
if (fileSize>=maxMultiPartSize) if (fileSize>=maxMultiPartSize)
{ {
qWarning("HttpRequest: received too many multipart bytes"); qWarning("HttpRequest::readBody: received too many multipart bytes");
status=abort; status=abort;
} }
else if (fileSize>=expectedBodySize) else if (fileSize>=expectedBodySize)
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: received whole multipart body"); qDebug("HttpRequest::readBody: received whole multipart body");
#endif #endif
tempFile->flush(); tempFile->flush();
if (tempFile->error()) if (tempFile->error())
{ {
qCritical("HttpRequest: Error writing temp file for multipart body"); qCritical("HttpRequest::readBody: Error writing temp file for multipart body");
} }
parseMultiPartFile(); parseMultiPartFile();
tempFile->close(); tempFile->close();
@ -228,7 +228,7 @@ void HttpRequest::readBody(QTcpSocket* socket)
void HttpRequest::decodeRequestParams() void HttpRequest::decodeRequestParams()
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: extract and decode request parameters"); qDebug("HttpRequest::decodeRequestParams: extract and decode request parameters");
#endif #endif
// Get URL parameters // Get URL parameters
QByteArray rawParameters; QByteArray rawParameters;
@ -274,7 +274,7 @@ void HttpRequest::decodeRequestParams()
void HttpRequest::extractCookies() void HttpRequest::extractCookies()
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: extract cookies"); qDebug("HttpRequest::extractCookies");
#endif #endif
foreach(QByteArray cookieStr, headers.values("cookie")) foreach(QByteArray cookieStr, headers.values("cookie"))
{ {
@ -282,7 +282,7 @@ void HttpRequest::extractCookies()
foreach(QByteArray part, list) foreach(QByteArray part, list)
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: found cookie %s",part.data()); qDebug("HttpRequest::extractCookies: found cookie %s",part.data());
#endif // Split the part into name and value #endif // Split the part into name and value
QByteArray name; QByteArray name;
QByteArray value; QByteArray value;
@ -320,7 +320,7 @@ void HttpRequest::readFromSocket(QTcpSocket* socket)
} }
if ((boundary.isEmpty() && currentSize>maxSize) || (!boundary.isEmpty() && currentSize>maxMultiPartSize)) if ((boundary.isEmpty() && currentSize>maxSize) || (!boundary.isEmpty() && currentSize>maxMultiPartSize))
{ {
qWarning("HttpRequest: received too many bytes"); qWarning("HttpRequest::readFromSocket: received too many bytes");
status=abort; status=abort;
} }
if (status==complete) if (status==complete)
@ -419,13 +419,13 @@ QByteArray HttpRequest::urlDecode(const QByteArray source)
void HttpRequest::parseMultiPartFile() void HttpRequest::parseMultiPartFile()
{ {
qDebug("HttpRequest: parsing multipart temp file"); qDebug("HttpRequest::parseMultiPartFile: parsing multipart temp file");
tempFile->seek(0); tempFile->seek(0);
bool finished=false; bool finished=false;
while (!tempFile->atEnd() && !finished && !tempFile->error()) while (!tempFile->atEnd() && !finished && !tempFile->error())
{ {
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: reading multpart headers"); qDebug("HttpRequest::parseMultiPartFile: reading multpart headers");
#endif #endif
QByteArray fieldName; QByteArray fieldName;
QByteArray fileName; QByteArray fileName;
@ -449,12 +449,12 @@ void HttpRequest::parseMultiPartFile()
fileName=line.mid(start+11,end-start-11); fileName=line.mid(start+11,end-start-11);
} }
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: multipart field=%s, filename=%s",fieldName.data(),fileName.data()); qDebug("HttpRequest::parseMultiPartFile: multipart field=%s, filename=%s",fieldName.data(),fileName.data());
#endif #endif
} }
else else
{ {
qDebug("HttpRequest: ignoring unsupported content part %s",line.data()); qDebug("HttpRequest::parseMultiPartFile: ignoring unsupported content part %s",line.data());
} }
} }
else if (line.isEmpty()) else if (line.isEmpty())
@ -464,7 +464,7 @@ void HttpRequest::parseMultiPartFile()
} }
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: reading multpart data"); qDebug("HttpRequest::parseMultiPartFile: reading multpart data");
#endif #endif
QTemporaryFile* uploadedFile=0; QTemporaryFile* uploadedFile=0;
QByteArray fieldValue; QByteArray fieldValue;
@ -486,15 +486,15 @@ void HttpRequest::parseMultiPartFile()
{ {
// last field was a file // last field was a file
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: finishing writing to uploaded file"); qDebug("HttpRequest::parseMultiPartFile: finishing writing to uploaded file");
#endif #endif
uploadedFile->resize(uploadedFile->size()-2); uploadedFile->resize(uploadedFile->size()-2);
uploadedFile->flush(); uploadedFile->flush();
uploadedFile->seek(0); uploadedFile->seek(0);
parameters.insert(fieldName,fileName); parameters.insert(fieldName,fileName);
qDebug("HttpRequest: set parameter %s=%s",fieldName.data(),fileName.data()); qDebug("HttpRequest::parseMultiPartFile: set parameter %s=%s",fieldName.data(),fileName.data());
uploadedFiles.insert(fieldName,uploadedFile); uploadedFiles.insert(fieldName,uploadedFile);
qDebug("HttpRequest: uploaded file size is %i",(int) uploadedFile->size()); qDebug("HttpRequest::parseMultiPartFile: uploaded file size is %i",(int) uploadedFile->size());
} }
if (line.contains(boundary+"--")) if (line.contains(boundary+"--"))
{ {
@ -521,7 +521,7 @@ void HttpRequest::parseMultiPartFile()
uploadedFile->write(line); uploadedFile->write(line);
if (uploadedFile->error()) if (uploadedFile->error())
{ {
qCritical("HttpRequest: error writing temp file, %s",qPrintable(uploadedFile->errorString())); qCritical("HttpRequest::parseMultiPartFile: error writing temp file, %s",qPrintable(uploadedFile->errorString()));
} }
} }
} }
@ -529,10 +529,10 @@ void HttpRequest::parseMultiPartFile()
} }
if (tempFile->error()) if (tempFile->error())
{ {
qCritical("HttpRequest: cannot read temp file, %s",qPrintable(tempFile->errorString())); qCritical("HttpRequest::parseMultiPartFile: cannot read temp file, %s",qPrintable(tempFile->errorString()));
} }
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
qDebug("HttpRequest: finished parsing multipart temp file"); qDebug("HttpRequest::parseMultiPartFile: finished parsing multipart temp file");
#endif #endif
} }

View File

@ -90,7 +90,7 @@ void StaticFileController::service(QByteArray& path, HttpResponse& response)
// Forbid access to files outside the docroot directory // Forbid access to files outside the docroot directory
if (path.contains("/..")) if (path.contains("/.."))
{ {
qWarning("StaticFileController: detected forbidden characters in path %s",path.data()); qWarning("StaticFileController::service: detected forbidden characters in path %s",path.data());
response.setStatus(403,"forbidden"); response.setStatus(403,"forbidden");
response.write("403 forbidden",true); response.write("403 forbidden",true);
return; return;
@ -137,13 +137,13 @@ void StaticFileController::service(QByteArray& path, HttpResponse& response)
else { else {
if (file.exists()) if (file.exists())
{ {
qWarning("StaticFileController: Cannot open existing file %s for reading",qPrintable(file.fileName())); qWarning("StaticFileController::service: Cannot open existing file %s for reading",qPrintable(file.fileName()));
response.setStatus(403,"forbidden"); response.setStatus(403,"forbidden");
response.write("403 forbidden",true); response.write("403 forbidden",true);
} }
else else
{ {
qWarning("StaticFileController: File %s not found",qPrintable(file.fileName())); qWarning("StaticFileController::service: File %s not found",qPrintable(file.fileName()));
response.setStatus(404,"not found"); response.setStatus(404,"not found");
response.write("404 not found",true); response.write("404 not found",true);
} }