> I have seen clients set the local date from there when ntp was not
available.

I'm just curious, could you please provide more details. What was the type
of clients? Embedded devices or something else.
Why wasn't ntp available for them? How often does this happen in the wild?
Can clients fetch the date from some website on the internet?
Anyways this is a hack but if someone really needs and control webserver
then it they can use a CGI script:

#!/bin/sh
# RFC date must have GMT in the end
# but GNU date return +0000 instead and bb date returns UTC
# So we must strip +0000 or UTC and add GMT ourselves
DATE=$(date -R -u | sed 's/\UTC//g' | sed 's/\+0000//g')
DATE="${DATE}GMT"
echo "Date: $DATE";
echo "Status: 200";
echo "";

Just put the script to /cgi-bin/date.sh and call it like
curl http://localhost:8080/cgi-bin/date.sh -v
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /cgi-bin/date.sh HTTP/1.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sat, 29 Aug 2020 19:32:21 GMT
< Status: 200

And BTW as you might notice the date command in BB looks like broken: it
should return date like:
$ date -R -u
Sat, 29 Aug 2020 19:34:38 +0000

but it returns
$ busybox date -R -u
Sat, 29 Aug 2020 19:35:12 UTC

IMHO BB date works correctly but to keep compatibility with GNU date
probably it should be changed





On Tue, 25 Aug 2020 at 11:54, Guillermo Rodriguez Garcia <
guille.rodrig...@gmail.com> wrote:

> Just for the record, I think that it is not correct to say that the
> Date header only makes sense for Cache-Control.
> There might be other uses for it; for example I have seen clients set
> the local date from there when ntp was not available.
> There could be other uses too; there is no way to know what people is
> using it for since it is mandated by RFC2616 and thus can be assumed
> to be always there.
>
> Guillermo
>
> El dom., 9 ago. 2020 a las 0:24, Sergey Ponomarev
> (<stok...@gmail.com>) escribió:
> >
> > In RFC 2616 sec. 14.18 said that sever MUST send Date header.
> > But in fact the header have sense only for Cache-Control and can be
> omitted.
> > In the same time the Date eats power, CPU and network resources which
> are critical for embedded systems.
> >
> > Signed-off-by: Sergey Ponomarev <stok...@gmail.com>
> > ---
> >  networking/httpd.c | 20 +++++++++++++++-----
> >  1 file changed, 15 insertions(+), 5 deletions(-)
> >
> > diff --git a/networking/httpd.c b/networking/httpd.c
> > index 9141442c8..7a429d2b5 100644
> > --- a/networking/httpd.c
> > +++ b/networking/httpd.c
> > @@ -214,6 +214,14 @@
> >  //config:      help
> >  //config:      Makes httpd send files using GZIP content encoding if the
> >  //config:      client supports it and a pre-compressed <file>.gz exists.
> > +//config:
> > +//config:config FEATURE_HTTPD_DATE
> > +//config:      bool "Add Date header to response"
> > +//config:      default y
> > +//config:      depends on HTTPD
> > +//config:      help
> > +//config:      RFC2616 says that sever MUST add Date header to response.
> > +//config:      But it is almost useless and can be omitted.
> >
> >  //applet:IF_HTTPD(APPLET(httpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
> >
> > @@ -1071,16 +1079,18 @@ static void send_headers(unsigned responseNum)
> >          * always fit into those kbytes.
> >          */
> >
> > -       strftime(date_str, sizeof(date_str), RFC1123FMT,
> gmtime_r(&timer, &tm));
> > -       /* ^^^ using gmtime_r() instead of gmtime() to not use static
> data */
> >         len = sprintf(iobuf,
> >                         "HTTP/1.1 %u %s\r\n"
> > -                       "Date: %s\r\n"
> >                         "Connection: close\r\n",
> > -                       responseNum, responseString,
> > -                       date_str
> > +                       responseNum, responseString
> >         );
> >
> > +#if ENABLE_FEATURE_HTTPD_DATE
> > +       strftime(date_str, sizeof(date_str), RFC1123FMT,
> gmtime_r(&timer, &tm));
> > +       /* ^^^ using gmtime_r() instead of gmtime() to not use static
> data */
> > +       len += sprintf(iobuf + len, "Date: %s\r\n", date_str);
> > +#endif
> > +
> >         if (responseNum != HTTP_OK || found_mime_type) {
> >                 len += sprintf(iobuf + len,
> >                                 "Content-type: %s\r\n",
> > --
> > 2.25.1
> >
> > _______________________________________________
> > busybox mailing list
> > busybox@busybox.net
> > http://lists.busybox.net/mailman/listinfo/busybox
>
>
>
> --
> Guillermo Rodriguez Garcia
> guille.rodrig...@gmail.com
>


-- 
Sergey Ponomarev <https://linkedin.com/in/stokito>, skype:stokito
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to