display traffic volume since last visit
This commit is contained in:
+14
-2
@@ -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, ¤tTrafficVolume) );
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user