Permalink
Browse files

* THttpServer: add getTimeRFC1123 method instead of hardcoded time :)

  • Loading branch information...
1 parent 0a9068c commit 7bdeecf8414d73a83a5c068cce92f62a304eca3f Jérémie BORDIER committed Jan 4, 2009
Showing with 17 additions and 1 deletion.
  1. +16 −1 lib/cpp/src/transport/THttpServer.cpp
  2. +1 −0 lib/cpp/src/transport/THttpServer.h
@@ -73,7 +73,7 @@ void THttpServer::flush() {
std::ostringstream h;
h <<
"HTTP/1.1 200 Ok" << CRLF <<
- "Date: Fri, 02 Jan 2009 19:09:44 GMT" << CRLF <<
+ "Date: " << getTimeRFC1123() << CRLF <<
"Server: Thrift/0.1" << CRLF <<
"Content-Type: application/x-thrift" << CRLF <<
"Content-Length: " << len << CRLF <<
@@ -92,4 +92,19 @@ void THttpServer::flush() {
readHeaders_ = true;
}
+std::string THttpServer::getTimeRFC1123()
+{
+ static const char* Days[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
+ static const char* Months[] = {"Jan","Feb","Mar", "Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct","Nov","Dec"};
+ char buff[128];
+ time_t t = time(NULL);
+ tm* broken_t = gmtime(&t);
+
+ sprintf(buff,"%s, %d %s %d %d:%d:%d GMT",
+ Days[broken_t->tm_wday], broken_t->tm_mday, Months[broken_t->tm_mon],
+ broken_t->tm_year + 1900,
+ broken_t->tm_hour,broken_t->tm_min,broken_t->tm_sec);
+ return std::string(buff);
+}
+
}}} // facebook::thrift::transport
@@ -29,6 +29,7 @@ class THttpServer : public THttpTransport {
void readHeaders();
virtual void parseHeader(char* header);
virtual bool parseStatusLine(char* status);
+ std::string getTimeRFC1123();
};

0 comments on commit 7bdeecf

Please sign in to comment.