Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/src/HttpResponseImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,13 @@ std::shared_ptr<trantor::MsgBuffer> HttpResponseImpl::renderToBuffer()
{
auto now = trantor::Date::now();
bool isDateChanged =
((now.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC) !=
httpStringDate_);
((now.microSecondsSinceEpoch() /
trantor::Date::MICRO_SECONDS_PER_SEC) != httpStringDate_);
assert(httpString_);
if (isDateChanged)
{
httpStringDate_ =
now.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC;
httpStringDate_ = now.microSecondsSinceEpoch() /
trantor::Date::MICRO_SECONDS_PER_SEC;
auto newDate = utils::getHttpFullDate(now);

httpString_ =
Expand Down
11 changes: 7 additions & 4 deletions lib/src/Utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@ char *getHttpFullDate(const trantor::Date &date)
{
static thread_local int64_t lastSecond = 0;
static thread_local char lastTimeString[128] = {0};
auto nowSecond = date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC;
auto nowSecond =
date.microSecondsSinceEpoch() / trantor::Date::MICRO_SECONDS_PER_SEC;
if (nowSecond == lastSecond)
{
return lastTimeString;
Expand All @@ -1038,7 +1039,8 @@ void dateToCustomFormattedString(const std::string &fmtStr,
std::string &str,
const trantor::Date &date)
{
auto nowSecond = date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC;
auto nowSecond =
date.microSecondsSinceEpoch() / trantor::Date::MICRO_SECONDS_PER_SEC;
struct tm tm_LValue = date.tmStruct();
std::stringstream Out;
Out.imbue(std::locale{"C"});
Expand All @@ -1050,7 +1052,8 @@ const std::string &getHttpFullDateStr(const trantor::Date &date)
{
static thread_local int64_t lastSecond = 0;
static thread_local std::string lastTimeString(128, 0);
auto nowSecond = date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC;
auto nowSecond =
date.microSecondsSinceEpoch() / trantor::Date::MICRO_SECONDS_PER_SEC;
if (nowSecond == lastSecond)
{
return lastTimeString;
Expand Down Expand Up @@ -1080,7 +1083,7 @@ trantor::Date getHttpDate(const std::string &httpFullDateString)
if (strptime(httpFullDateString.c_str(), format, &tmptm) != NULL)
{
auto epoch = timegm(&tmptm);
return trantor::Date(epoch * MICRO_SECONDS_PRE_SEC);
return trantor::Date(epoch * trantor::Date::MICRO_SECONDS_PER_SEC);
}
}
LOG_WARN << "invalid datetime format: '" << httpFullDateString << "'";
Expand Down
12 changes: 9 additions & 3 deletions lib/tests/unittests/HttpDateTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ DROGON_TEST(HttpDate)
{
// RFC 850
auto date = utils::getHttpDate("Fri, 05-Jun-20 09:19:38 GMT");
CHECK(date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC == 1591348778);
CHECK(date.microSecondsSinceEpoch() /
trantor::Date::MICRO_SECONDS_PER_SEC ==
1591348778);

// Reddit format
date = utils::getHttpDate("Fri, 05-Jun-2020 09:19:38 GMT");
CHECK(date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC == 1591348778);
CHECK(date.microSecondsSinceEpoch() /
trantor::Date::MICRO_SECONDS_PER_SEC ==
1591348778);

// Invalid
date = utils::getHttpDate("Fri, this format is invalid");
Expand All @@ -20,5 +24,7 @@ DROGON_TEST(HttpDate)
auto epoch = time(nullptr);
auto str = asctime(gmtime(&epoch));
date = utils::getHttpDate(str);
CHECK(date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC == epoch);
CHECK(date.microSecondsSinceEpoch() /
trantor::Date::MICRO_SECONDS_PER_SEC ==
epoch);
}
Loading