aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r--src/daemon/connection.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index 5139ae0c..505e4aad 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Daniel Pittman 3 (C) 2007 Daniel Pittman and Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -880,10 +880,10 @@ MHD_add_extra_headers(struct MHD_Connection * connection) {
880 880
881 if (connection->response->total_size == -1) { 881 if (connection->response->total_size == -1) {
882 have = MHD_get_response_header(connection->response, 882 have = MHD_get_response_header(connection->response,
883 "Connection"); 883 MHD_HTTP_HEADER_CONNECTION);
884 if (have == NULL) 884 if (have == NULL)
885 MHD_add_response_header(connection->response, 885 MHD_add_response_header(connection->response,
886 "Connection", 886 MHD_HTTP_HEADER_CONNECTION,
887 "close"); 887 "close");
888 } else if (NULL == MHD_get_response_header(connection->response, 888 } else if (NULL == MHD_get_response_header(connection->response,
889 MHD_HTTP_HEADER_CONTENT_LENGTH)) { 889 MHD_HTTP_HEADER_CONTENT_LENGTH)) {
@@ -894,7 +894,28 @@ MHD_add_extra_headers(struct MHD_Connection * connection) {
894 MHD_add_response_header(connection->response, 894 MHD_add_response_header(connection->response,
895 MHD_HTTP_HEADER_CONTENT_LENGTH, 895 MHD_HTTP_HEADER_CONTENT_LENGTH,
896 buf); 896 buf);
897 } 897 }
898}
899
900static void get_date_string(char * date,
901 unsigned int max) {
902 static const char * days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
903 static const char * mons[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
904 struct tm now;
905 time_t t;
906
907 time(&t);
908 gmtime_r(&t, &now);
909 snprintf(date,
910 max-1,
911 "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n",
912 days[now.tm_wday % 7],
913 now.tm_mday,
914 mons[now.tm_mon % 12],
915 now.tm_year,
916 now.tm_hour,
917 now.tm_min,
918 now.tm_sec);
898} 919}
899 920
900/** 921/**
@@ -908,6 +929,7 @@ MHD_build_header_response(struct MHD_Connection * connection) {
908 size_t off; 929 size_t off;
909 struct MHD_HTTP_Header * pos; 930 struct MHD_HTTP_Header * pos;
910 char code[32]; 931 char code[32];
932 char date[128];
911 char * data; 933 char * data;
912 934
913 MHD_add_extra_headers(connection); 935 MHD_add_extra_headers(connection);
@@ -923,6 +945,12 @@ MHD_build_header_response(struct MHD_Connection * connection) {
923 size += strlen(pos->header) + strlen(pos->value) + 4; /* colon, space, linefeeds */ 945 size += strlen(pos->header) + strlen(pos->value) + 4; /* colon, space, linefeeds */
924 pos = pos->next; 946 pos = pos->next;
925 } 947 }
948 if (NULL == MHD_get_response_header(connection->response,
949 MHD_HTTP_HEADER_DATE))
950 get_date_string(date, sizeof(date));
951 else
952 date[0] = '\0';
953 size += strlen(date);
926 /* produce data */ 954 /* produce data */
927 data = MHD_pool_allocate(connection->pool, 955 data = MHD_pool_allocate(connection->pool,
928 size + 1, 956 size + 1,
@@ -944,6 +972,9 @@ MHD_build_header_response(struct MHD_Connection * connection) {
944 off += strlen(pos->header) + strlen(pos->value) + 4; 972 off += strlen(pos->header) + strlen(pos->value) + 4;
945 pos = pos->next; 973 pos = pos->next;
946 } 974 }
975 strcpy(&data[off],
976 date);
977 off += strlen(date);
947 sprintf(&data[off], 978 sprintf(&data[off],
948 "\r\n"); 979 "\r\n");
949 off += 2; 980 off += 2;