* Better control of HTTP headers which control browser caches. Static
authorArt Cancro <ajc@citadel.org>
Wed, 23 Feb 2005 05:08:20 +0000 (05:08 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 23 Feb 2005 05:08:20 +0000 (05:08 +0000)
  objects are getting properly cached now.

webcit/ChangeLog
webcit/webcit.c
webcit/webcit.h
webcit/webserver.c

index 84fa12225d926abae6e28b1e16ed74b636f5d259..d21b51a386e702974ace9036e616eddd7865c3ad 100644 (file)
@@ -1,4 +1,8 @@
 $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.
@@ -2437,4 +2441,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index 90777a928bff14375d6b814441bfd6afe2bce071..c22bddb69cdebf9d445be190b0cf6213421284e2 100644 (file)
@@ -364,13 +364,23 @@ void output_headers(      int do_httpheaders,     /* 1 = output HTTP headers
 
        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,
@@ -469,20 +479,44 @@ void check_for_instant_messages()
  */
 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);
 }
index aaf670b8fe09b34487018ad131fd8b0852b44c2b..c7ab8d30ddcb99c036a7b5f356bd06795f5220a8 100644 (file)
@@ -493,6 +493,13 @@ int client_read_ssl(char *buf, int bytes, int timeout);
 void client_write_ssl(char *buf, int nbytes);
 #endif
 
+#ifdef HAVE_ZLIB
+#include <zlib.h>
+int ZEXPORT compress_gzip(Bytef * dest, uLongf * destLen,
+                          const Bytef * source, uLong sourceLen, int level);
+#endif
+
+
 void begin_burst(void);
 void end_burst(void);
 
index ef9733141e353d134f92d194f2c69dee5056965e..360062d117facb682e5f5b0282178e9dd812bfbd 100644 (file)
 #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
@@ -289,7 +285,7 @@ void end_burst(void)
                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;