# HG changeset patch # User Arne Babenhauserheide # Date 1617535342 -7200 # Sun Apr 04 13:22:22 2021 +0200 # Node ID 95b674a7fb114f5305e871afb1049db4edfa7f0f # Parent b6063cb779a632b6bcf8bcb65621f7ee8d42723b use UTF-8 for known text formats diff --git a/wispserve/serve.w b/wispserve/serve.w --- a/wispserve/serve.w +++ b/wispserve/serve.w @@ -410,16 +410,18 @@ 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 @@ . '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