[plt-scheme] patch to web-server-unit.ss for last-modified header

From: joe-cs-brown-edu at elem.com (joe-cs-brown-edu at elem.com)
Date: Fri Apr 25 02:30:57 EDT 2003

I wrote a little patch to web-server-unit.ss version 203 to include a
last-modified header when serving a file.  This helps browsers and
proxy caches cache static content.  It's what apache does by default.

Not sure exactly who maintains this module, so here it is (below) for
anyone who wants it.  I hope this functionality will make it into the
next release.

Thanks to the mz/plt team for creating such a nice development
platform!

- Joe

--- plt.203/collects/web-server/web-server-unit.ss	2002-11-23 01:38:26.000000000 -0800
+++ plt/collects/web-server/web-server-unit.ss	2003-04-24 23:16:23.000000000 -0700
@@ -449,12 +449,15 @@
       ; to serve out the file
       (define (output-file method path out timer host-info close)
         (let ([size (file-size path)]
+              [last-modified (seconds->gmt-string
+                              (file-or-directory-modify-seconds path))]
               [timeouts (host-timeouts host-info)])
           (reset-timer timer (+ (timeouts-file-base timeouts) (* size (timeouts-file-per-byte timeouts))))
           (output-headers out 200 "Okay" 
                           (file-or-directory-modify-seconds path)
                           (get-mime-type path)
-                          `(("Content-length: " ,size))
+                          `(("Content-length: " ,size)
+                            ("Last-modified: " ,last-modified))
                           close))
         (when (eq? method 'get)
           (call-with-input-file path (lambda (in) (copy-port in out)))))


Posted on the users mailing list.