mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 03:38:03 +08:00
Optimize function getHttpFullDate()
This commit is contained in:
parent
efb7fce2b9
commit
94b76120a5
@ -32,7 +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);
|
||||
char * getHttpFullDate(const trantor::Date &date);
|
||||
std::string formattedString(const char *format,...);
|
||||
|
||||
}
|
||||
|
@ -362,18 +362,17 @@ void HttpResponseImpl::appendToBuffer(MsgBuffer* output) const
|
||||
output->append("Date: ");
|
||||
output->append(getHttpFullDate(trantor::Date::date()));
|
||||
output->append("\r\n");
|
||||
|
||||
|
||||
if(_cookies.size() > 0) {
|
||||
for(auto it = _cookies.begin(); it != _cookies.end(); it++) {
|
||||
|
||||
output->append(it->second.cookieString());
|
||||
}
|
||||
}
|
||||
// output->append("Server: drogon/");
|
||||
// output->append(drogon::getVersion());
|
||||
// output->append("\r\n\r\n");
|
||||
output->append("Server: drogon/");
|
||||
output->append(drogon::getVersion());
|
||||
output->append("\r\n\r\n");
|
||||
|
||||
output->append("\r\n");
|
||||
LOG_TRACE<<"reponse(no body):"<<output->peek();
|
||||
output->append(_body);
|
||||
|
||||
|
@ -306,12 +306,21 @@ namespace drogon{
|
||||
*ndata = d_stream.total_out;
|
||||
return 0;
|
||||
}
|
||||
std::string getHttpFullDate(const trantor::Date &date)
|
||||
char * 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");
|
||||
static __thread uint64_t lastSecond=0;
|
||||
static __thread char lastTimeString[128]={0};
|
||||
auto nowSecond=date.microSecondsSinceEpoch()/MICRO_SECONDS_PRE_SEC;
|
||||
if(nowSecond==lastSecond)
|
||||
{
|
||||
return lastTimeString;
|
||||
}
|
||||
lastSecond=nowSecond;
|
||||
date.toCustomedFormattedString("%a, %d %b %Y %T GMT",lastTimeString,sizeof(lastTimeString));
|
||||
return lastTimeString;
|
||||
}
|
||||
std::string formattedString(const char *format,...)
|
||||
{
|
||||
|
2
trantor
2
trantor
@ -1 +1 @@
|
||||
Subproject commit 9fe1163f535ec8a229a8a37cc059e1b500bde51c
|
||||
Subproject commit fe58a81e34b34991d1f356718dd99616c0859716
|
Loading…
Reference in New Issue
Block a user