From 2d797e7b5e22d6502226e6cd9cf8eb2fc0a2454f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 8 Aug 2007 20:48:41 +0000 Subject: fixing 1261 --- src/daemon/connection.c | 39 +++++++++++++++++++++++++++++++++++---- src/daemon/connection.h | 2 +- src/daemon/daemon.c | 2 +- src/daemon/internal.c | 2 +- src/daemon/internal.h | 2 +- src/daemon/memorypool.c | 2 +- src/daemon/memorypool.h | 2 +- src/daemon/response.c | 2 +- src/daemon/response.h | 2 +- 9 files changed, 43 insertions(+), 12 deletions(-) (limited to 'src/daemon') 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 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -880,10 +880,10 @@ MHD_add_extra_headers(struct MHD_Connection * connection) { if (connection->response->total_size == -1) { have = MHD_get_response_header(connection->response, - "Connection"); + MHD_HTTP_HEADER_CONNECTION); if (have == NULL) MHD_add_response_header(connection->response, - "Connection", + MHD_HTTP_HEADER_CONNECTION, "close"); } else if (NULL == MHD_get_response_header(connection->response, MHD_HTTP_HEADER_CONTENT_LENGTH)) { @@ -894,7 +894,28 @@ MHD_add_extra_headers(struct MHD_Connection * connection) { MHD_add_response_header(connection->response, MHD_HTTP_HEADER_CONTENT_LENGTH, buf); - } + } +} + +static void get_date_string(char * date, + unsigned int max) { + static const char * days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + static const char * mons[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + struct tm now; + time_t t; + + time(&t); + gmtime_r(&t, &now); + snprintf(date, + max-1, + "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n", + days[now.tm_wday % 7], + now.tm_mday, + mons[now.tm_mon % 12], + now.tm_year, + now.tm_hour, + now.tm_min, + now.tm_sec); } /** @@ -908,6 +929,7 @@ MHD_build_header_response(struct MHD_Connection * connection) { size_t off; struct MHD_HTTP_Header * pos; char code[32]; + char date[128]; char * data; MHD_add_extra_headers(connection); @@ -923,6 +945,12 @@ MHD_build_header_response(struct MHD_Connection * connection) { size += strlen(pos->header) + strlen(pos->value) + 4; /* colon, space, linefeeds */ pos = pos->next; } + if (NULL == MHD_get_response_header(connection->response, + MHD_HTTP_HEADER_DATE)) + get_date_string(date, sizeof(date)); + else + date[0] = '\0'; + size += strlen(date); /* produce data */ data = MHD_pool_allocate(connection->pool, size + 1, @@ -944,6 +972,9 @@ MHD_build_header_response(struct MHD_Connection * connection) { off += strlen(pos->header) + strlen(pos->value) + 4; pos = pos->next; } + strcpy(&data[off], + date); + off += strlen(date); sprintf(&data[off], "\r\n"); off += 2; diff --git a/src/daemon/connection.h b/src/daemon/connection.h index 59b99004..840ae640 100644 --- a/src/daemon/connection.h +++ b/src/daemon/connection.h @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 48ec9219..57035fd1 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/src/daemon/internal.c b/src/daemon/internal.c index eed1acba..ef67affc 100644 --- a/src/daemon/internal.c +++ b/src/daemon/internal.c @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/src/daemon/internal.h b/src/daemon/internal.h index 1c3525f6..57e5ebf1 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/src/daemon/memorypool.c b/src/daemon/memorypool.c index 5b54cd2e..d8e835e8 100644 --- a/src/daemon/memorypool.c +++ b/src/daemon/memorypool.c @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/src/daemon/memorypool.h b/src/daemon/memorypool.h index c49e0d8e..693b03f6 100644 --- a/src/daemon/memorypool.h +++ b/src/daemon/memorypool.h @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/src/daemon/response.c b/src/daemon/response.c index 4bbe0f36..b816a8a5 100644 --- a/src/daemon/response.c +++ b/src/daemon/response.c @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/src/daemon/response.h b/src/daemon/response.h index c865951f..ab582f00 100644 --- a/src/daemon/response.h +++ b/src/daemon/response.h @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Daniel Pittman + (C) 2007 Daniel Pittman and Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published -- cgit v1.2.3