display traffic volume since last visit

This commit is contained in:
acetone
2022-11-22 12:24:41 +03:00
parent 237c7a87d0
commit c4bb96adb0
8 changed files with 52 additions and 12 deletions
+14 -2
View File
@@ -26,6 +26,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
constexpr const int getValueBeforeSpaceLIMIT = 200;
constexpr const int getValueBeforeBodyLIMIT = 1000;
constexpr const char* lastTrafficVolumeCookie = "trafficvolume";
SocketRunnable::SocketRunnable(qintptr socketDescriptor, QObject *parent) :
SocketRunnableBase(socketDescriptor, parent)
{
@@ -35,7 +37,17 @@ void SocketRunnable::get()
{
if (urlPath() == "/index.html")
{
httpDocument().setBody(WebPage::document());
quint64 lastTrafficVolume = 0;
const QString cookieString = g::getValue(m_headers, "Cookie", g::GetValueType::HttpHeader);
if (not cookieString.isEmpty())
{
lastTrafficVolume = g::getValue(m_headers, lastTrafficVolumeCookie).toULongLong();
}
quint64 currentTrafficVolume = 0;
httpDocument().setBody( WebPage::document(lastTrafficVolume, &currentTrafficVolume) );
httpDocument().setHeader(HttpDocument::CommonHeader::SetCookie,
QString(lastTrafficVolumeCookie)+"="+QString::number(currentTrafficVolume)+"; max-age=31536000;");
return;
}
@@ -79,7 +91,7 @@ void SocketRunnable::reader()
}
else if (reqType != "HEAD")
{
httpDocument().setCode(HttpDocument::Code::_400); // default code is 200
httpDocument().setCode(HttpDocument::Code::_400);
}
setDataToWrite(httpDocument().document());