-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added additional formats for getHttpDate function and fixed undefined…
… behavior upon error (#453) (#456) This patch adds support for the RFC 850 and asctime format. If an error occurs, we now return a date with the epoch value of -1 and warn instead of triggering undefined behavior. This is checked by a new set of tests. Co-authored-by: VayuDev <vayudev@protonmail.com> Co-authored-by: antao <antao2002@gmail.com>
- Loading branch information
1 parent
5faab6b
commit d4d5adf
Showing
6 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <drogon/utils/Utilities.h> | ||
#include <gtest/gtest.h> | ||
using namespace drogon; | ||
|
||
TEST(HttpDate, rfc850) | ||
{ | ||
auto date = utils::getHttpDate("Fri, 05-Jun-20 09:19:38 GMT"); | ||
EXPECT_EQ(date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC, 1591348778); | ||
} | ||
|
||
TEST(HttpDate, redditFormat) | ||
{ | ||
auto date = utils::getHttpDate("Fri, 05-Jun-2020 09:19:38 GMT"); | ||
EXPECT_EQ(date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC, 1591348778); | ||
} | ||
|
||
TEST(HttpDate, invalidFormat) | ||
{ | ||
auto date = utils::getHttpDate("Fri, this format is invalid"); | ||
EXPECT_EQ(date.microSecondsSinceEpoch(), (std::numeric_limits<int64_t>::max)()); | ||
} | ||
|
||
TEST(HttpDate, asctimeFormat) | ||
{ | ||
auto epoch = time(nullptr); | ||
auto str = asctime(gmtime(&epoch)); | ||
auto date = utils::getHttpDate(str); | ||
EXPECT_EQ(date.microSecondsSinceEpoch() / MICRO_SECONDS_PRE_SEC, epoch); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |