HEAD and POST request processing
parent
bf602d6554
commit
f558c0f0ff
4
main.cpp
4
main.cpp
|
@ -7,14 +7,14 @@
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 3) {
|
||||
qDebug() << "Usage: <address-to-bind> <port>";
|
||||
qInfo() << "Usage: <address-to-bind> <port>";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
// ACII MODERN ART
|
||||
qDebug().noquote() <<"\
|
||||
qInfo().noquote() <<"\
|
||||
+---------------------------------------+\n\
|
||||
| _ __ ___ __ _ _ __ _ ___ |\n\
|
||||
| | '_ ` _ \\ / _` | '__| |/ _ \\ |\n\
|
||||
|
|
31
resolver.cpp
31
resolver.cpp
|
@ -25,7 +25,7 @@ Resolver::Resolver(const QString& addr, quint16 port, QObject* parent) :
|
|||
throw "Server not binded";
|
||||
}
|
||||
|
||||
qDebug().noquote() << "<-" << m_tcpServer->serverAddress().toString() + " : " +
|
||||
qInfo().noquote() << "<-" << m_tcpServer->serverAddress().toString() + " : " +
|
||||
QString::number(m_tcpServer->serverPort()) << "[" + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") + "]";
|
||||
|
||||
connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(slotNewUser()));
|
||||
|
@ -41,7 +41,7 @@ void Resolver::closeSocketViaDescriptor(int id)
|
|||
QSharedPointer<QTcpSocket> Resolver::getSocketViaDescriptor(int id)
|
||||
{
|
||||
if (!m_sockets.contains(id)) {
|
||||
qDebug() << "Resolver::getSocketViaDescriptor: Requested socket not found";
|
||||
qInfo() << "Resolver::getSocketViaDescriptor: Requested socket not found";
|
||||
}
|
||||
return m_sockets.value(id);
|
||||
}
|
||||
|
@ -61,14 +61,25 @@ void Resolver::slotReadyClient()
|
|||
{
|
||||
QTcpSocket* clientSocket = static_cast<QTcpSocket*>(sender());
|
||||
QString req(clientSocket->readAll());
|
||||
qDebug().noquote() << "\n->" << clientSocket->peerAddress().toString()
|
||||
qInfo().noquote() << "\n->" << clientSocket->peerAddress().toString()
|
||||
<< "[" + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") + "]";
|
||||
|
||||
bool web = req.startsWith("GET /");
|
||||
if (req.startsWith("POST /")) {
|
||||
qInfo().noquote() << " └ POST request (dropped)";
|
||||
clientSocket->close();
|
||||
return;
|
||||
}
|
||||
QSharedPointer<QTextStream> ts(new QTextStream(clientSocket));
|
||||
if (req.startsWith("HEAD /")) {
|
||||
qInfo().noquote() << " └ HEAD request";
|
||||
*ts << http::HEADER_OK;
|
||||
clientSocket->close();
|
||||
return;
|
||||
}
|
||||
|
||||
bool web = req.startsWith("GET /");
|
||||
if (web) {
|
||||
qDebug().noquote() << " └ Via web browser";
|
||||
qInfo().noquote() << " └ Via web browser";
|
||||
if (req.contains("toConverting=")) {
|
||||
processPage(req, ts, web);
|
||||
} else {
|
||||
|
@ -77,7 +88,7 @@ void Resolver::slotReadyClient()
|
|||
} else {
|
||||
req.remove('\r');
|
||||
req.remove('\n');
|
||||
qDebug().noquote() << " └ Without web browser";
|
||||
qInfo().noquote() << " └ Without web browser";
|
||||
if (req.contains(":") or req.contains(".")) {
|
||||
processPage(req, ts, web);
|
||||
} else {
|
||||
|
@ -151,7 +162,7 @@ void Resolver::startPage(QSharedPointer<QTextStream> ts, bool web)
|
|||
{
|
||||
QTcpSocket* clientSocket = static_cast<QTcpSocket*>(sender());
|
||||
if (web) {
|
||||
qDebug().noquote() << " └ Start page";
|
||||
qInfo().noquote() << " └ Start page";
|
||||
QString page = http::HTML_PAGE;
|
||||
QString css = http::CSS_DEFAULT;
|
||||
css.replace("{{COLOR}}", "gray");
|
||||
|
@ -161,7 +172,7 @@ void Resolver::startPage(QSharedPointer<QTextStream> ts, bool web)
|
|||
*ts << page;
|
||||
}
|
||||
else {
|
||||
qDebug().noquote() << " └ Incorrect request";
|
||||
qInfo().noquote() << " └ Incorrect request";
|
||||
*ts << "{\n"
|
||||
" \"status\": false,\n"
|
||||
" \"answer\": \"Push any domain to resolve or IPv6 to convert to meship\"\n"
|
||||
|
@ -173,7 +184,7 @@ void Resolver::startPage(QSharedPointer<QTextStream> ts, bool web)
|
|||
|
||||
void Resolver::startPageWithMessage(const QString & value, QSharedPointer<QTextStream> ts, const QString & msg, bool web)
|
||||
{
|
||||
qDebug().noquote() << " └ " + msg;
|
||||
qInfo().noquote() << " └ " + msg;
|
||||
|
||||
if (web) {
|
||||
QString page = http::HTML_PAGE;
|
||||
|
@ -206,7 +217,7 @@ void Resolver::processPage(const QString& req, QSharedPointer<QTextStream> ts, b
|
|||
value.remove('+');
|
||||
value = QByteArray::fromPercentEncoding(value.toUtf8());
|
||||
|
||||
qDebug().noquote() << " └ " + value;
|
||||
qInfo().noquote() << " └ " + value;
|
||||
const uint8_t MAX_LEN = 60;
|
||||
if (value.size() > MAX_LEN) {
|
||||
startPageWithMessage("", ts, "Maximum input value length = " + QString::number(MAX_LEN), web);
|
||||
|
|
Loading…
Reference in New Issue