From 7227e55dbadade25696ee5f416786861fc058826 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 5 Oct 2012 00:17:40 +0200 Subject: [PATCH] ENABLE_HTTP_DATE : add a Date: header to all HTTP responses --- miniupnpd/Changelog.txt | 5 ++++- miniupnpd/genconfig.sh | 10 +++++++++- miniupnpd/upnphttp.c | 20 +++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index 916ecd6..f841ae3 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,4 +1,7 @@ -$Id: Changelog.txt,v 1.309 2012/09/27 16:01:10 nanard Exp $ +$Id: Changelog.txt,v 1.318 2012/10/04 22:11:55 nanard Exp $ + +2012/10/03: + ENABLE_HTTP_DATE : add a Date: header to all HTTP responses 2012/09/27: Fixes with DISABLE_CONFIG_FILE diff --git a/miniupnpd/genconfig.sh b/miniupnpd/genconfig.sh index bce40ea..3e72848 100755 --- a/miniupnpd/genconfig.sh +++ b/miniupnpd/genconfig.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: genconfig.sh,v 1.58 2012/06/29 19:29:55 nanard Exp $ +# $Id: genconfig.sh,v 1.61 2012/10/03 21:07:29 nanard Exp $ # miniupnp daemon # http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/ # (c) 2006-2012 Thomas Bernard @@ -410,6 +410,14 @@ else fi echo "" >> ${CONFIGFILE} +echo "/* Add the optional Date: header in all HTTP responses */" >> ${CONFIGFILE} +if [ -n "$STRICT" ] ; then + echo "#define ENABLE_HTTP_DATE" >> ${CONFIGFILE} +else + echo "/*#define ENABLE_HTTP_DATE*/" >> ${CONFIGFILE} +fi +echo "" >> ${CONFIGFILE} + echo "/* disable reading and parsing of config file (miniupnpd.conf) */" >> ${CONFIGFILE} echo "/*#define DISABLE_CONFIG_FILE*/" >> ${CONFIGFILE} echo "" >> ${CONFIGFILE} diff --git a/miniupnpd/upnphttp.c b/miniupnpd/upnphttp.c index 248e325..3849644 100644 --- a/miniupnpd/upnphttp.c +++ b/miniupnpd/upnphttp.c @@ -1,4 +1,4 @@ -/* $Id: upnphttp.c,v 1.76 2012/09/27 13:15:03 nanard Exp $ */ +/* $Id: upnphttp.c,v 1.81 2012/10/04 22:09:34 nanard Exp $ */ /* Project : miniupnp * Website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * Author : Thomas Bernard @@ -19,6 +19,9 @@ #include #include #include "config.h" +#ifdef ENABLE_HTTP_DATE +#include +#endif #include "upnphttp.h" #include "upnpdescgen.h" #include "miniupnpdpath.h" @@ -730,6 +733,21 @@ BuildHeader_upnphttp(struct upnphttp * h, int respcode, /* Content-Type MUST be 'text/xml; charset="utf-8"' according to UDA v1.1 */ /* Content-Type MUST be 'text/xml' according to UDA v1.0 */ /* Additional headers */ +#ifdef ENABLE_HTTP_DATE + { + char http_date[64]; + time_t t; + struct tm tm; + time(&t); + gmtime_r(&t, &tm); + /* %a and %b depend on locale */ + strftime(http_date, sizeof(http_date), + "%a, %d %b %Y %H:%M:%S GMT", &tm); + h->res_buflen += snprintf(h->res_buf + h->res_buflen, + h->res_buf_alloclen - h->res_buflen, + "Date: %s\r\n", http_date); + } +#endif #ifdef ENABLE_EVENTS if(h->respflags & FLAG_TIMEOUT) { h->res_buflen += snprintf(h->res_buf + h->res_buflen,