1
0
ithewei 6 жил өмнө
parent
commit
c75efacd2c

+ 1 - 1
base/hversion.c

@@ -5,7 +5,7 @@
 const char* get_compile_version() {
     static char s_version[64] = {0};
     datetime_t dt = get_compile_datetime();
-    snprintf(s_version, sizeof(s_version), "%d.%02d.%02d.%02d",
+    snprintf(s_version, sizeof(s_version), "%d.%d.%d.%d",
         H_VERSION_MAJOR, dt.year%100, dt.month, dt.day);
     return s_version;
 }

+ 5 - 0
http/HttpRequest.h

@@ -363,6 +363,11 @@ public:
         snprintf(c_str, sizeof(c_str), "HTTP/%d.%d %d %s\r\n", http_major, http_minor, status_code, http_status_str(status_code));
         str += c_str;
         if (is_dump_headers) {
+            // Date:
+            time_t tt;
+            time(&tt);
+            strftime(c_str, sizeof(c_str), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&tt));
+            headers["Date"] = c_str;
             dump_headers(str);
         }
         str += "\r\n";

+ 6 - 6
http/server/http_server.cpp

@@ -50,6 +50,12 @@ static void on_read(hio_t* io, void* buf, int readbytes) {
     if (parser->get_state() == HP_MESSAGE_COMPLETE) {
         handler->handle_request();
         // prepare header body
+        // Server:
+        static char s_Server[64] = {'\0'};
+        if (s_Server[0] == '\0') {
+            snprintf(s_Server, sizeof(s_Server), "httpd/%s", get_compile_version());
+        }
+        handler->res.headers["Server"] = s_Server;
         // Connection:
         bool keepalive = true;
         auto iter = handler->req.headers.find("connection");
@@ -67,12 +73,6 @@ static void on_read(hio_t* io, void* buf, int readbytes) {
         else {
             handler->res.headers["Connection"] = "close";
         }
-        // Date:
-        time_t tt;
-        time(&tt);
-        char c_str[256] = {0};
-        strftime(c_str, sizeof(c_str), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&tt));
-        handler->res.headers["Date"] = c_str;
         std::string header = handler->res.dump(true, false);
         hbuf_t sendbuf;
         bool send_in_one_packet = true;