Bozohttpd

Check-in [a29fb4fb10]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Initial work on setting Cache-Control headers

The bit that foxed me was understanding getopts and that the "h" needed a ":"
after it because the option accepts and argument. It'll happily build and run
without this, but segfault when you try to use a "-h" argument.

This definitely and utterly sets a header. It doesn't seem that it's recognised
properly for whatever reason though, e.g here:

- https://developers.google.com/speed/pagespeed/insights/

and here:

- http://highloadtools.com/cachecontrol

But what can you do?

At the moment this just sets a header everywhere for everything being served.
What would be better would be just setting this on certain file types.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a29fb4fb10ecaeea65aecf2c9b78a47a4720396a
User & Date: atomicules 2017-11-25 19:08:28
Context
2017-11-25
22:13
Set cache-control only for images

A bit of an intermediate commit, just investigating what works. I think really
need to be able to pass in a string and a cache-control header and it'll use
strstr to determine which header to set. I.e so you can pass in:

"image" "max-age=604800"
"css" "max-age=86400"

The bit I'm then missing is how to set a catch all or "owtelse" cache-control?
Maybe look for one argument? check-in: dda2552f49 user: atomicules tags: trunk

19:08
Initial work on setting Cache-Control headers

The bit that foxed me was understanding getopts and that the "h" needed a ":"
after it because the option accepts and argument. It'll happily build and run
without this, but segfault when you try to use a "-h" argument.

This definitely and utterly sets a header. It doesn't seem that it's recognised
properly for whatever reason though, e.g here:

- https://developers.google.com/speed/pagespeed/insights/

and here:

- http://highloadtools.com/cachecontrol

But what can you do?

At the moment this just sets a header everywhere for everything being served.
What would be better would be just setting this on certain file types. check-in: a29fb4fb10 user: atomicules tags: trunk

2017-11-24
21:16
Add version 20170201 of Bozohttpd check-in: b786821675 user: atomicules tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bozohttpd.c.

1733
1734
1735
1736
1737
1738
1739


1740
1741
1742
1743
1744
1745
1746
....
2313
2314
2315
2316
2317
2318
2319



2320
2321
2322
2323
2324
2325
2326
		struct	tm *tm;

		tm = gmtime(&sbp->st_mtime);
		strftime(filedate, sizeof filedate,
		    "%a, %d %b %Y %H:%M:%S GMT", tm);
		bozo_printf(httpd, "Last-Modified: %s\r\n", filedate);
	}


	if (type && *type)
		bozo_printf(httpd, "Content-Type: %s\r\n", type);
	if (encoding && *encoding)
		bozo_printf(httpd, "Content-Encoding: %s\r\n", encoding);
	if (sbp) {
		if (request->hr_have_range) {
			len = request->hr_last_byte_pos -
................................................................................
	}
	if ((cp = bozo_get_pref(prefs, "directory indexing")) != NULL &&
	    strcmp(cp, "true") == 0) {
		httpd->dir_indexing = 1;
	}
	if ((cp = bozo_get_pref(prefs, "public_html")) != NULL) {
		httpd->public_html = bozostrdup(httpd, NULL, cp);



	}
	httpd->server_software =
	    bozostrdup(httpd, NULL, bozo_get_pref(prefs, "server software"));
	httpd->index_html =
	    bozostrdup(httpd, NULL, bozo_get_pref(prefs, "index.html"));

	/*







>
>







 







>
>
>







1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
....
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
		struct	tm *tm;

		tm = gmtime(&sbp->st_mtime);
		strftime(filedate, sizeof filedate,
		    "%a, %d %b %Y %H:%M:%S GMT", tm);
		bozo_printf(httpd, "Last-Modified: %s\r\n", filedate);
	}
	if (httpd->cache_control_headers)
		bozo_printf(httpd, "Cache-Control: %s\r\n", httpd->cache_control_headers);
	if (type && *type)
		bozo_printf(httpd, "Content-Type: %s\r\n", type);
	if (encoding && *encoding)
		bozo_printf(httpd, "Content-Encoding: %s\r\n", encoding);
	if (sbp) {
		if (request->hr_have_range) {
			len = request->hr_last_byte_pos -
................................................................................
	}
	if ((cp = bozo_get_pref(prefs, "directory indexing")) != NULL &&
	    strcmp(cp, "true") == 0) {
		httpd->dir_indexing = 1;
	}
	if ((cp = bozo_get_pref(prefs, "public_html")) != NULL) {
		httpd->public_html = bozostrdup(httpd, NULL, cp);
	}
	if ((cp = bozo_get_pref(prefs, "Cache-Control headers")) != NULL) {
		httpd->cache_control_headers = bozostrdup(httpd, NULL, cp);
	}
	httpd->server_software =
	    bozostrdup(httpd, NULL, bozo_get_pref(prefs, "server software"));
	httpd->index_html =
	    bozostrdup(httpd, NULL, bozo_get_pref(prefs, "index.html"));

	/*

Changes to bozohttpd.h.

113
114
115
116
117
118
119

120
121
122
123
124
125
126
	int		 nsock;		/* number of above */
	struct pollfd	*fds;		/* current poll fd set */
	int		 request_times;	/* # times a request was processed */
	int		 dir_indexing;	/* handle directories */
	int		 hide_dots;	/* hide .* */
	int		 process_cgi;	/* use the cgi handler */
	char		*cgibin;	/* cgi-bin directory */

#ifndef NO_LUA_SUPPORT
	int		 process_lua;	/* use the Lua handler */
	SIMPLEQ_HEAD(, lua_state_map)	lua_states;
#endif
	void		*sslinfo;	/* pointer to ssl struct */
	int		dynamic_content_map_size;/* size of dyn cont map */
	bozo_content_map_t	*dynamic_content_map;/* dynamic content map */







>







113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
	int		 nsock;		/* number of above */
	struct pollfd	*fds;		/* current poll fd set */
	int		 request_times;	/* # times a request was processed */
	int		 dir_indexing;	/* handle directories */
	int		 hide_dots;	/* hide .* */
	int		 process_cgi;	/* use the cgi handler */
	char		*cgibin;	/* cgi-bin directory */
	char		*cache_control_headers;	/* Cache-Control headers */
#ifndef NO_LUA_SUPPORT
	int		 process_lua;	/* use the Lua handler */
	SIMPLEQ_HEAD(, lua_state_map)	lua_states;
#endif
	void		*sslinfo;	/* pointer to ssl struct */
	int		dynamic_content_map_size;/* size of dyn cont map */
	bozo_content_map_t	*dynamic_content_map;/* dynamic content map */

Changes to main.c.

90
91
92
93
94
95
96

97
98
99
100
101
102
103
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
...
189
190
191
192
193
194
195




196
197
198
199
200
201
202
	bozowarn(httpd, "   -b\t\t\tbackground and go into daemon mode");
	bozowarn(httpd, "   -f\t\t\tkeep daemon mode in the foreground");
	bozowarn(httpd,
		"   -i address\t\tbind on this address (daemon mode only)");
	bozowarn(httpd, "   -P pidfile\t\tpath to the pid file to create");
#endif
	bozowarn(httpd, "   -S version\t\tset server version string");

	bozowarn(httpd, "   -t dir\t\tchroot to `dir'");
	bozowarn(httpd, "   -U username\t\tchange user to `user'");
	bozowarn(httpd,
		"   -e\t\t\tdon't clean the environment (-t and -U only)");
	bozowarn(httpd,
		"   -v virtualroot\tenable virtual host support "
		"in this directory");
................................................................................
	bozo_set_defaults(&httpd, &prefs);

	/*
	 * -r option was removed, do not reuse it for a while
	 */

	while ((c = getopt(argc, argv,
	    "C:EGHI:L:M:P:S:U:VXZ:bc:defhi:np:st:uv:x:z:")) != -1) {
		switch (c) {

		case 'L':
#ifdef NO_LUA_SUPPORT
			bozoerr(&httpd, 1,
				"Lua support is not enabled");
			/* NOTREACHED */
................................................................................
			bozo_set_pref(&httpd, &prefs, "log to stderr", "true");
			break;

		case 'S':
			bozo_set_pref(&httpd, &prefs, "server software",
				      optarg);
			break;




		case 'Z':
#ifdef NO_SSL_SUPPORT
			bozoerr(&httpd, 1, "ssl support is not enabled");
			/* NOT REACHED */
#else
			/* make sure there's two arguments */
			if (argc - optind < 1)







>







 







|







 







>
>
>
>







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
	bozowarn(httpd, "   -b\t\t\tbackground and go into daemon mode");
	bozowarn(httpd, "   -f\t\t\tkeep daemon mode in the foreground");
	bozowarn(httpd,
		"   -i address\t\tbind on this address (daemon mode only)");
	bozowarn(httpd, "   -P pidfile\t\tpath to the pid file to create");
#endif
	bozowarn(httpd, "   -S version\t\tset server version string");
	bozowarn(httpd, "   -h string\t\tCache-Control headers");
	bozowarn(httpd, "   -t dir\t\tchroot to `dir'");
	bozowarn(httpd, "   -U username\t\tchange user to `user'");
	bozowarn(httpd,
		"   -e\t\t\tdon't clean the environment (-t and -U only)");
	bozowarn(httpd,
		"   -v virtualroot\tenable virtual host support "
		"in this directory");
................................................................................
	bozo_set_defaults(&httpd, &prefs);

	/*
	 * -r option was removed, do not reuse it for a while
	 */

	while ((c = getopt(argc, argv,
	    "C:EGHI:L:M:P:S:U:VXZ:bc:defh:i:np:st:uv:x:z:")) != -1) {
		switch (c) {

		case 'L':
#ifdef NO_LUA_SUPPORT
			bozoerr(&httpd, 1,
				"Lua support is not enabled");
			/* NOTREACHED */
................................................................................
			bozo_set_pref(&httpd, &prefs, "log to stderr", "true");
			break;

		case 'S':
			bozo_set_pref(&httpd, &prefs, "server software",
				      optarg);
			break;
		case 'h':
			bozo_set_pref(&httpd, &prefs, "Cache-Control headers",
				      optarg);
			break;
		case 'Z':
#ifdef NO_SSL_SUPPORT
			bozoerr(&httpd, 1, "ssl support is not enabled");
			/* NOT REACHED */
#else
			/* make sure there's two arguments */
			if (argc - optind < 1)