$Log$
+Revision 603.3 2005/02/23 05:08:20 ajc
+* Better control of HTTP headers which control browser caches. Static
+ objects are getting properly cached now.
+
Revision 603.2 2005/02/22 05:15:28 ajc
* When the "begin_burst() / end_burst()" semantics are in use, perform
gzip compression when the client indicates support for it.
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
-
if (do_httpheaders) {
wprintf("Content-type: text/html\r\n"
- "Server: %s / %s\n", SERVER, serv_info.serv_software
+ "Server: %s / %s\n"
+ "Connection: close\r\n",
+ SERVER, serv_info.serv_software
+ );
+ }
+
+ if (cache) {
+ wprintf("Pragma: public\r\n"
+ "Cache-Control: max-age=3600, must-revalidate\r\n"
+ "Last-modified: %s\r\n",
+ httpnow
+ );
+ }
+ else {
+ wprintf("Pragma: no-cache\r\n"
+ "Cache-Control: no-store\r\n"
);
- if (!cache)
- wprintf("Connection: close\r\n"
- "Pragma: no-cache\r\n"
- "Cache-Control: no-store\r\n"
- );
}
stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
*/
void http_transmit_thing(char *thing, size_t length, char *content_type,
int is_static) {
- if (is_static) {
- output_headers(0, 0, 0, 0, 0, 0, 1);
- }
- else {
- output_headers(0, 0, 0, 0, 0, 0, 0);
- }
+
+ output_headers(0, 0, 0, 0, 0, 0, is_static);
+
wprintf("Content-type: %s\r\n"
- "Content-length: %ld\r\n"
"Server: %s\r\n"
- "Connection: close\r\n"
- "\r\n",
+ "Connection: close\r\n",
content_type,
- (long) length,
- SERVER
+ SERVER);
+
+#ifdef HAVE_ZLIB
+ /* If we can send the data out compressed, please do so. */
+ if (WC->gzip_ok) {
+ char *compressed_data = NULL;
+ uLongf compressed_len;
+
+ compressed_len = (uLongf) ((length * 101) / 100) + 100;
+ compressed_data = malloc(compressed_len);
+
+ if (compress_gzip((Bytef *) compressed_data,
+ &compressed_len,
+ (Bytef *) thing,
+ (uLongf) length, Z_BEST_SPEED) == Z_OK) {
+ wprintf("Content-encoding: gzip\r\n"
+ "Content-length: %ld\r\n"
+ "\r\n",
+ (long) compressed_len
+ );
+ client_write(compressed_data, (size_t)compressed_len);
+ free(compressed_data);
+ return;
+ }
+ }
+#endif
+
+ /* No compression ... just send it out as-is */
+ wprintf("Content-length: %ld\r\n"
+ "\r\n",
+ (long) length
);
client_write(thing, (size_t)length);
}
#include "webcit.h"
#include "webserver.h"
-#ifdef HAVE_ZLIB
-#include <zlib.h>
-#endif
-
#ifndef HAVE_SNPRINTF
int vsnprintf(char *buf, size_t max, const char *fmt, va_list argp);
#endif
if (compress_gzip((Bytef *) compressed_data,
&compressed_len,
(Bytef *) the_data,
- (uLongf) the_len, 9) == Z_OK) {
+ (uLongf) the_len, Z_BEST_SPEED) == Z_OK) {
wprintf("Content-encoding: gzip\r\n");
free(the_data);
the_data = compressed_data;