mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
adding content-type output for http server files
This commit is contained in:
parent
983829cab1
commit
7366a13413
4 changed files with 29 additions and 4 deletions
|
@ -144,5 +144,10 @@ Content-Transfer-Encoding: binary
|
||||||
--BbC04y--
|
--BbC04y--
|
||||||
--AaB03x--
|
--AaB03x--
|
||||||
"))))
|
"))))
|
||||||
|
(test "text/html; charset=utf-8"
|
||||||
|
(mime-type-from-extension "html"))
|
||||||
|
(test "text/plain; charset=utf-8"
|
||||||
|
(mime-type-from-extension "scm"))
|
||||||
|
(test #f
|
||||||
|
(mime-type-from-extension "foo"))
|
||||||
(test-end))))
|
(test-end))))
|
||||||
|
|
|
@ -21,6 +21,20 @@
|
||||||
(cond ((and (pair? ls) (pair? (car ls)) (assq key ls)) => cdr)
|
(cond ((and (pair? ls) (pair? (car ls)) (assq key ls)) => cdr)
|
||||||
(else (and (pair? o) (car o)))))
|
(else (and (pair? o) (car o)))))
|
||||||
|
|
||||||
|
;; most of these are plain text for easier viewing in the browser
|
||||||
|
(define (mime-type-from-extension ext)
|
||||||
|
(assq-ref
|
||||||
|
'((htm . "text/html; charset=utf-8")
|
||||||
|
(html . "text/html; charset=utf-8")
|
||||||
|
(scm . "text/plain; charset=utf-8")
|
||||||
|
(sld . "text/plain; charset=utf-8")
|
||||||
|
(c . "text/plain; charset=utf-8")
|
||||||
|
(h . "text/plain; charset=utf-8")
|
||||||
|
(txt . "text/plain; charset=utf-8")
|
||||||
|
(org . "text/plain; charset=utf-8")
|
||||||
|
(md . "text/plain; charset=utf-8"))
|
||||||
|
(and (string? ext) (string->symbol ext))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; simple matching instead of regexps
|
;; simple matching instead of regexps
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
(define-library (chibi mime)
|
(define-library (chibi mime)
|
||||||
(export assq-ref mime-header-fold mime-headers->list
|
(export assq-ref mime-header-fold mime-headers->list
|
||||||
mime-parse-content-type mime-decode-header
|
mime-parse-content-type mime-decode-header
|
||||||
mime-message-fold mime-message->sxml mime-write-headers)
|
mime-message-fold mime-message->sxml mime-write-headers
|
||||||
|
mime-type-from-extension)
|
||||||
(import (scheme base) (scheme char) (scheme write)
|
(import (scheme base) (scheme char) (scheme write)
|
||||||
(chibi base64) (chibi quoted-printable)
|
(chibi base64) (chibi quoted-printable)
|
||||||
(chibi string))
|
(chibi string))
|
||||||
|
|
|
@ -129,8 +129,13 @@
|
||||||
(define (http-send-file request path)
|
(define (http-send-file request path)
|
||||||
(cond
|
(cond
|
||||||
((file-exists? path)
|
((file-exists? path)
|
||||||
(servlet-respond request 200 "OK")
|
(let ((headers
|
||||||
(send-file path (request-out request)))
|
(cond
|
||||||
|
((mime-type-from-extension (path-extension path))
|
||||||
|
=> (lambda (type) `((Content-Type . ,type))))
|
||||||
|
(else '()))))
|
||||||
|
(servlet-respond request 200 "OK" headers)
|
||||||
|
(send-file path (request-out request))))
|
||||||
(else
|
(else
|
||||||
(servlet-respond request 404 "Not Found"))))
|
(servlet-respond request 404 "Not Found"))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue