Revision: 4671 Author: hans URL: http://bknr.net/trac/changeset/4671
Range handling fixes: Add "Accept-Ranges" header to static file responses, report range only in partial responses, Fix off-by-one errors (ranges are inclusive). Thanks to Wukix Inc. for reporting.
U trunk/thirdparty/hunchentoot/misc.lisp
Modified: trunk/thirdparty/hunchentoot/misc.lisp =================================================================== --- trunk/thirdparty/hunchentoot/misc.lisp 2011-08-29 05:42:50 UTC (rev 4670) +++ trunk/thirdparty/hunchentoot/misc.lisp 2011-08-29 07:11:05 UTC (rev 4671) @@ -139,10 +139,11 @@ (setf (return-code*) +http-requested-range-not-satisfiable+) (throw 'handler-done (format nil "invalid request range (requested ~D-~D, accepted 0-~D)" - start end (file-length file)))) + start end (1- (file-length file))))) (file-position file start) (setf (return-code*) +http-partial-content+ - bytes-to-send (1+ (- end start)))) + bytes-to-send (1+ (- end start)) + (header-out :content-range) (format nil "bytes ~D-~D/*" start end))) bytes-to-send))
(defun handle-static-file (pathname &optional content-type) @@ -162,14 +163,14 @@ (setf (content-type*) (or content-type (mime-type pathname) "application/octet-stream") - (header-out :last-modified) (rfc-1123-date time)) + (header-out :last-modified) (rfc-1123-date time) + (header-out :accept-ranges) "bytes") (handle-if-modified-since time) (with-open-file (file pathname :direction :input :element-type 'octet :if-does-not-exist nil) - (setf (header-out :content-range) (format nil "bytes 0-~D/*" (1- (file-length file))) - bytes-to-send (maybe-handle-range-header file) + (setf bytes-to-send (maybe-handle-range-header file) (content-length*) bytes-to-send) (let ((out (send-headers)) (buf (make-array +buffer-length+ :element-type 'octet)))