3

I am running busybox httpd with following command:

busybox httpd -p 80 -h /var/www

It works, however I need to set cache-control header to no cache.

Currently my server append only these headers:

  HTTP/1.0 200 OK
  Content-type: text/html
  Date: Thu, 28 Jun 2018 06:58:08 GMT
  Connection: close
  Accept-Ranges: bytes
  Last-Modified: Thu, 28 Jun 2018 06:57:43 GMT
  Content-Length: 45

How can I configure my busybox httpd server to append

Cache-Control: no-cache

header?

Jan Tajovsky
  • 132
  • 1
  • 6

2 Answers2

3

BusyBox HTTP Daemon (httpd) webserver is an own simple web server implementation without wide configuration options, as you can see from the OpenWRT configuration documentation or the comment block from httpd.c source (lines 39-60):

 * httpd.conf has the following format:
 *
 * H:/serverroot     # define the server root. It will override -h
 * A:172.20.         # Allow address from 172.20.0.0/16
 * A:10.0.0.0/25     # Allow any address from 10.0.0.0-10.0.0.127
 * A:10.0.0.0/255.255.255.128  # Allow any address that previous set
 * A:127.0.0.1       # Allow local loopback connections
 * D:*               # Deny from other IP connections
 * E404:/path/e404.html # /path/e404.html is the 404 (not found) error page
 * I:index.html      # Show index.html when a directory is requested
 *
 * P:/url:[http://]hostname[:port]/new/path
 *                   # When /urlXXXXXX is requested, reverse proxy
 *                   # it to http://hostname[:port]/new/pathXXXXXX
 *
 * /cgi-bin:foo:bar  # Require user foo, pwd bar on urls starting with /cgi-bin/
 * /adm:admin:setup  # Require user admin, pwd setup on urls starting with /adm/
 * /adm:toor:PaSsWd  # or user toor, pwd PaSsWd on urls starting with /adm/
 * /adm:root:*       # or user root, pwd from /etc/passwd on urls starting with /adm/
 * /wiki:*:*         # or any user from /etc/passwd with according pwd on urls...
 * .au:audio/basic   # additional mime type for audio.au files
 * *.php:/path/php   # run xxx.php through an interpreter

Your options with BusyBox HTTPd:

  • BusyBox HTTP Daemon is open source. Modify httpd.c to add the header and compile.
  • Have your page served as a cgi script. It can have custom headers at the beginning.

Or install some more versatile web server that has this: Nginx, Apache, Lighttpd...

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122
  • Is it possible to configure httpd to run cgi script for all request? From what I read, it does not seems to be possible (perhaps I am missing something???). – Jan Tajovsky Jun 28 '18 at 08:12
  • 1
    The configuration is limited to what's quoted here. You can do everything you want, but not through configuration, but through modifying the source code. It's much easier and sensible to add a single header than to modify the behavior with CGI scripts. – Esa Jokinen Jun 28 '18 at 08:40
-1

docker run -d --name busybox-http -p 8080:8080 -e TZ=UTC-8 busybox sh -c " echo GMT-8 > /etc/TZ mkdir -p /root/cgi-bin cat > /root/cgi-bin/a.html <<EOF #!/bin/sh echo -e 'Content-Type: text/plain\n' echo "hostname=[\$(hostname)], time=[\$(date '+%F %T')], query=[\${QUERY_STRING}], path=[\${PATH_INFO}]" echo "requestUrl=[\${REQUEST_URI}]" echo -e "\n=== env list:\n\$(env|sed 's/\n/
/g')" EOF chmod u+x /root/cgi-bin/a.html httpd -p 8081 -h /root cat > /root/httpd.conf <<EOF P:/:http://localhost:8081/cgi-bin/a.html/ EOF httpd -p 8080 -c /root/httpd.conf sleep infinty "

curl localhost:8080/a/b?c=1

Result Output:

hostname=[e95c54e5ff19], time=[2021-01-19 23:20:42], query=[c=1], path=[/a/b] requestUrl=[/cgi-bin/a.html/a/b?c=1]

=== env list: GATEWAY_INTERFACE=CGI/1.1 HOSTNAME=e95c54e5ff19 SHLVL=2 REMOTE_ADDR=[::ffff:127.0.0.1] HOME=/root QUERY_STRING=c=1 HTTP_USER_AGENT=curl/7.29.0 REMOTE_PORT=51456 HTTP_ACCEPT=/ SCRIPT_FILENAME=/root/cgi-bin/a.html HTTP_HOST=localhost:8080 REQUEST_URI=/cgi-bin/a.html/a/b?c=1 SERVER_SOFTWARE=busybox httpd/1.31.1 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin SERVER_PROTOCOL=HTTP/1.0 PATH_INFO=/a/b REQUEST_METHOD=GET PWD=/root/cgi-bin SCRIPT_NAME=/cgi-bin/a.html