mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
parent
051072ee46
commit
4a5b0b6bf2
@ -37,7 +37,7 @@ QString QtHttpClientWrapper::getGuid (void)
|
||||
{
|
||||
m_guid = QString::fromLocal8Bit (
|
||||
QCryptographicHash::hash (
|
||||
QByteArray::number ((quint64) (this)),
|
||||
QByteArray::number (reinterpret_cast<quint64>(this)),
|
||||
QCryptographicHash::Md5
|
||||
).toHex ()
|
||||
);
|
||||
@ -50,7 +50,7 @@ void QtHttpClientWrapper::onClientDataReceived (void)
|
||||
{
|
||||
if (m_sockClient != Q_NULLPTR)
|
||||
{
|
||||
while (m_sockClient->bytesAvailable ())
|
||||
while (m_sockClient->bytesAvailable () != 0)
|
||||
{
|
||||
QByteArray line = m_sockClient->readLine ();
|
||||
|
||||
@ -62,9 +62,9 @@ void QtHttpClientWrapper::onClientDataReceived (void)
|
||||
QStringList parts = QStringUtils::split(str,SPACE, QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
if (parts.size () == 3)
|
||||
{
|
||||
QString command = parts.at (0);
|
||||
QString url = parts.at (1);
|
||||
QString version = parts.at (2);
|
||||
const QString& command = parts.at (0);
|
||||
const QString& url = parts.at (1);
|
||||
const QString& version = parts.at (2);
|
||||
|
||||
if (version == QtHttpServer::HTTP_VERSION)
|
||||
{
|
||||
@ -85,31 +85,35 @@ void QtHttpClientWrapper::onClientDataReceived (void)
|
||||
m_parsingStatus = ParsingError;
|
||||
// Error : incorrect HTTP command line
|
||||
}
|
||||
m_fragment.clear();
|
||||
|
||||
break;
|
||||
}
|
||||
case AwaitingHeaders: // "header: value" × N (until empty line)
|
||||
{
|
||||
QByteArray raw = line.trimmed ();
|
||||
m_fragment.append(line);
|
||||
|
||||
if ( m_fragment.endsWith(CRLF))
|
||||
{
|
||||
QByteArray raw = m_fragment.trimmed ();
|
||||
if (!raw.isEmpty ()) // parse headers
|
||||
{
|
||||
int pos = raw.indexOf (COLON);
|
||||
|
||||
if (pos > 0)
|
||||
{
|
||||
QByteArray header = raw.left (pos).trimmed();
|
||||
QByteArray value = raw.mid (pos +1).trimmed();
|
||||
m_currentRequest->addHeader (header, value);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
if (header.compare(QtHttpHeader::ContentLength, Qt::CaseInsensitive) == 0)
|
||||
#else
|
||||
if (header.toLower() == QtHttpHeader::ContentLength.toLower())
|
||||
#endif
|
||||
{
|
||||
bool ok = false;
|
||||
const int len = value.toInt (&ok, 10);
|
||||
if (ok)
|
||||
bool isConversionOk = false;
|
||||
const int len = value.toInt (&isConversionOk, 10);
|
||||
if (isConversionOk)
|
||||
{
|
||||
m_currentRequest->addHeader (QtHttpHeader::ContentLength, QByteArray::number (len));
|
||||
}
|
||||
@ -132,6 +136,8 @@ void QtHttpClientWrapper::onClientDataReceived (void)
|
||||
m_parsingStatus = RequestParsed;
|
||||
}
|
||||
}
|
||||
m_fragment.clear();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -157,7 +163,7 @@ void QtHttpClientWrapper::onClientDataReceived (void)
|
||||
case RequestParsed: // a valid request has ben fully parsed
|
||||
{
|
||||
// Catch websocket header "Upgrade"
|
||||
if(m_currentRequest->getHeader(QtHttpHeader::Upgrade) == "websocket")
|
||||
if(m_currentRequest->getHeader(QtHttpHeader::Upgrade).toLower() == "websocket")
|
||||
{
|
||||
if(m_websocketClient == Q_NULLPTR)
|
||||
{
|
||||
@ -315,10 +321,9 @@ QtHttpClientWrapper::ParsingStatus QtHttpClientWrapper::sendReplyToClient (QtHtt
|
||||
{
|
||||
if (!reply->useChunked ())
|
||||
{
|
||||
//reply->appendRawData (CRLF);
|
||||
// send all headers and all data in one shot
|
||||
reply->requestSendHeaders ();
|
||||
reply->requestSendData ();
|
||||
emit reply->requestSendHeaders ();
|
||||
emit reply->requestSendData ();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -331,7 +336,7 @@ QtHttpClientWrapper::ParsingStatus QtHttpClientWrapper::sendReplyToClient (QtHtt
|
||||
{
|
||||
static const QByteArray & CLOSE = QByteArrayLiteral ("close");
|
||||
|
||||
if (m_currentRequest->getHeader(QtHttpHeader::Connection) == CLOSE)
|
||||
if (m_currentRequest->getHeader(QtHttpHeader::Connection).toLower() == CLOSE)
|
||||
{
|
||||
// must close connection after this request
|
||||
m_sockClient->close ();
|
||||
|
@ -58,6 +58,7 @@ private:
|
||||
const bool m_localConnection;
|
||||
WebSocketClient * m_websocketClient;
|
||||
WebJsonRpc * m_webJsonRpc;
|
||||
QByteArray m_fragment;
|
||||
};
|
||||
|
||||
#endif // QTHTTPCLIENTWRAPPER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user