Modify date format(rfc2616-3.3.1)

This commit is contained in:
antao 2018-09-11 17:31:10 +08:00
parent 2afb875d86
commit 67e62a743b
5 changed files with 21 additions and 15 deletions

View File

@ -14,9 +14,11 @@
#pragma once
#include <trantor/utils/Date.h>
#include <uuid.h>
#include <string>
#include <vector>
namespace drogon{
bool isInteger(const std::string &str);
std::string genRandomString(int length);
@ -30,6 +32,7 @@ namespace drogon{
char *zdata, size_t *nzdata);
int gzipDecompress(const char *zdata, const size_t nzdata,
char *data, size_t *ndata);
std::string getHttpFullDate(const trantor::Date &date);
}

View File

@ -13,6 +13,7 @@
*/
#include <drogon/Cookie.h>
#include <drogon/utils/Utilities.h>
using namespace drogon;
const std::string Cookie::cookieString() const
{
@ -21,14 +22,14 @@ const std::string Cookie::cookieString() const
if(_expiresDate.microSecondsSinceEpoch()>0)
{
//add expiresDate string
struct tm tm1=_expiresDate.tmStruct();
char timeBuf[64];
asctime_r(&tm1,timeBuf);
std::string timeStr(timeBuf);
std::string::size_type len=timeStr.length();
timeStr =timeStr.substr(0,len-1)+" GMT";
// struct tm tm1=_expiresDate.tmStruct();
// char timeBuf[64];
// asctime_r(&tm1,timeBuf);
// std::string timeStr(timeBuf);
// std::string::size_type len=timeStr.length();
// timeStr =timeStr.substr(0,len-1)+" GMT";
ret.append("Expires= ").append(timeStr).append("; ");
ret.append("Expires= ").append(getHttpFullDate(_expiresDate)).append("; ");
}
if(!_domain.empty())
{

View File

@ -33,6 +33,7 @@
#include <trantor/utils/MsgBuffer.h>
#include <trantor/net/InetAddress.h>
#include <trantor/utils/Date.h>
#include <drogon/utils/Utilities.h>
#include <map>
#include <string>
@ -50,13 +51,7 @@ namespace drogon
_left_body_length(0),
_current_chunk_length(0)
{
struct tm tm1=trantor::Date::date().tmStruct();
char timeBuf[64];
asctime_r(&tm1,timeBuf);
std::string timeStr(timeBuf);
std::string::size_type len=timeStr.length();
timeStr =timeStr.substr(0,len-1)+" GMT";
addHeader("Date",timeStr);
_headers["Date"]=getHttpFullDate(trantor::Date::date());
}
virtual HttpStatusCode statusCode() override
{

View File

@ -303,5 +303,12 @@ namespace drogon{
*ndata = d_stream.total_out;
return 0;
}
std::string getHttpFullDate(const trantor::Date &date)
{
//rfc2616-3.3.1
//Full Date format like this:Sun, 06 Nov 1994 08:49:37 GMT
// Wed, 12 Sep 2018 09:22:40 GMT
return date.toCustomedFormattedString("%a, %d %b %Y %T GMT");
}
}

View File

@ -1,4 +1,4 @@
link_libraries(drogon trantor pthread)
link_libraries(drogon trantor uuid pthread jsoncpp dl z)
add_executable(cache_map_test CacheMapTest.cc)
add_executable(cookies_test CookiesTest.cc)