@@ 410,16 410,18 @@ list "</ul></body></html>\n"
define : get-file-chunk abspath begin end
. "open the file, seek to BEGIN, return bytearray from BEGIN to END, inclusive"
+ define mime-type : guess-mime-type abspath
+ define binary : binary? mime-type
if : not : file-exists? abspath
. ""
- let : : port : open-input-file abspath #:binary #t
+ let : : port : open-input-file abspath #:binary binary
seek port begin SEEK_SET
let : : data : if end (get-bytevector-n port (+ 1 (- end begin))) (get-bytevector-all port)
close port
;; pretty-print : list abspath begin end data
if : eof-object? data
. ""
- bytevector->string data "ISO-8859-1"
+ bytevector->string data : charset mime-type
define : join-path-elements-safely path-elements
. "Remove every .. and / from the path elements and join as path"
@@ 465,13 467,17 @@ define : guess-mime-type path
. 'video/webm
else mime-type
+define : charset mime-type
+ cond
+ : member mime-type '(text/html text/plain application/x-mpegurl)
+ . "UTF-8"
+ else "ISO-8859-1"
+
define : content-type mime-type
- define charset
- cond
- : member mime-type '(text/html text/plain application/x-mpegurl)
- . "utf-8"
- else "ISO-8859-1"
- ` ,mime-type (charset . ,charset)
+ ` ,mime-type (charset . ,(charset mime-type))
+
+define : binary? mime-type
+ equal? "ISO-8859-1" : charset mime-type
define : hash-and-mime-if-unknown! served-file
define accesspath : and=> (and=> served-file cdr) served-accesspath