Changeset 12025 in project
- Timestamp:
- 09/28/08 20:12:58 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
release/4/spiffy/trunk/spiffy.scm
r12024 r12025 62 62 (define mime-type-map 63 63 (make-parameter 64 '(("txt" . text/plain) 65 ("xml" . text/xml) 66 ("xul" . application/vnd.mozilla.xul+xml) 67 ("htm" . text/html) 64 '(("xml" . text/xml) 68 65 ("html" . text/html) 66 ("xhtml" . text/xhtml+xml) 69 67 ("js" . text/javascript) 70 68 ("pdf" . application/pdf) 71 69 ("css" . text/css) 72 (" bmp" . image/bmp)70 ("png" . image/png) 73 71 ("ico" . image/x-icon) 74 72 ("gif" . image/gif) 73 ("jpeg" . image/jpeg) 75 74 ("jpg" . image/jpeg) 76 ("jpeg" . image/jpeg) 77 ("png" . image/png)))) 75 ("svg" . image/svg+xml) 76 ("bmp" . image/bmp) 77 ("txt" . text/plain) 78 ("htm" . text/html)))) 78 79 (define default-mime-type (make-parameter 'application/octet-stream)) 79 80 (define default-host (make-parameter "localhost")) ;; XXX Can we do without? 81 (define file-extension-handlers (make-parameter '())) 80 82 81 83 ;;; Custom handlers … … 87 89 (make-parameter 88 90 (lambda (path) 89 (with-headers `((content-type ,(extension->mime-type 90 (pathname-extension path)))) 91 (lambda () 92 (send-static-file path)))))) 91 (let* ((ext (pathname-extension path)) 92 (handler (alist-ref ext (file-extension-handlers) 93 string-ci=? send-static-file))) 94 ;; Should we modify the content-type here or later on? 95 (with-headers `((content-type ,(extension->mime-type ext))) 96 (lambda () (handler path))))))) 93 97 (define handle-not-found 94 98 (make-parameter … … 97 101 "The resource you requested could not be found")))) 98 102 99 100 103 ;;; Internal parameters 101 104 (define request-restarter (make-parameter #f)) 105 106 (define (extension->mime-type ext) 107 (alist-ref (or ext "") (mime-type-map) string-ci=? (default-mime-type))) 102 108 103 109 ;; A simple utility procedure to render a status code with message … … 136 142 (file-close fd)))))) 137 143 138 (define (extension->mime-type ext)139 (alist-ref (or ext "") (mime-type-map) string-ci=? (default-mime-type)))140 141 144 (define (with-headers new-headers thunk) 142 145 (parameterize ((current-response
Note: See TracChangeset
for help on using the changeset viewer.