cleaned up http server
parent
8a0d30605b
commit
e365e16537
|
|
@ -47,7 +47,6 @@ void DevicePluginHttpCommander::setupDevice(DeviceSetupInfo *info)
|
||||||
//: Error setting up device
|
//: Error setting up device
|
||||||
return info->finish(Device::DeviceErrorInvalidParameter, QT_TR_NOOP("The given url is not valid."));
|
return info->finish(Device::DeviceErrorInvalidParameter, QT_TR_NOOP("The given url is not valid."));
|
||||||
}
|
}
|
||||||
|
|
||||||
return info->finish(Device::DeviceErrorNoError);
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ HttpSimpleServer::HttpSimpleServer(QObject *parent):
|
||||||
HttpSimpleServer::~HttpSimpleServer()
|
HttpSimpleServer::~HttpSimpleServer()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpSimpleServer::incomingConnection(qintptr socket)
|
void HttpSimpleServer::incomingConnection(qintptr socket)
|
||||||
|
|
@ -68,42 +67,13 @@ void HttpSimpleServer::readClient()
|
||||||
|
|
||||||
QByteArray data = tcpSocket->readAll();
|
QByteArray data = tcpSocket->readAll();
|
||||||
QStringList tokens = QString(data).split(QRegExp("[ \r\n][ \r\n]*"));
|
QStringList tokens = QString(data).split(QRegExp("[ \r\n][ \r\n]*"));
|
||||||
//QUrl url("http://foo.bar" + tokens[1]);
|
|
||||||
//QUrlQuery query(url);
|
|
||||||
qCDebug(dcHttpCommander()) << "Http Request, type" << tokens[0] << "path" << tokens[1] << "body" << tokens.last();
|
qCDebug(dcHttpCommander()) << "Http Request, type" << tokens[0] << "path" << tokens[1] << "body" << tokens.last();
|
||||||
|
|
||||||
if (tokens[0] == "GET") {
|
if ((tokens[0] == "GET") ||
|
||||||
QTextStream os(tcpSocket);
|
(tokens[0] == "PUT") ||
|
||||||
os.setAutoDetectUnicode(true);
|
(tokens[0] == "POST") ||
|
||||||
os << generateHeader();
|
(tokens[0] == "DELETE")) {
|
||||||
tcpSocket->close();
|
|
||||||
|
|
||||||
if (tcpSocket->state() == QTcpSocket::UnconnectedState)
|
|
||||||
delete tcpSocket;
|
|
||||||
|
|
||||||
emit requestReceived(tokens[0], tokens[1], tokens.last());
|
|
||||||
} else if (tokens[0] == "PUT") {
|
|
||||||
QTextStream os(tcpSocket);
|
|
||||||
os.setAutoDetectUnicode(true);
|
|
||||||
os << generateHeader();
|
|
||||||
tcpSocket->close();
|
|
||||||
|
|
||||||
if (tcpSocket->state() == QTcpSocket::UnconnectedState)
|
|
||||||
delete tcpSocket;
|
|
||||||
|
|
||||||
emit requestReceived(tokens[0], tokens[1], tokens.last());
|
|
||||||
|
|
||||||
} else if (tokens[0] == "POST") {
|
|
||||||
QTextStream os(tcpSocket);
|
|
||||||
os.setAutoDetectUnicode(true);
|
|
||||||
os << generateHeader();
|
|
||||||
tcpSocket->close();
|
|
||||||
|
|
||||||
if (tcpSocket->state() == QTcpSocket::UnconnectedState)
|
|
||||||
delete tcpSocket;
|
|
||||||
emit requestReceived(tokens[0], tokens[1], tokens.last());
|
|
||||||
|
|
||||||
} else if (tokens[0] == "DELETE") {
|
|
||||||
QTextStream os(tcpSocket);
|
QTextStream os(tcpSocket);
|
||||||
os.setAutoDetectUnicode(true);
|
os.setAutoDetectUnicode(true);
|
||||||
os << generateHeader();
|
os << generateHeader();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue