Changeset 12025 in project


Ignore:
Timestamp:
09/28/08 20:12:58 (11 years ago)
Author:
sjamaan
Message:

Tweak file extension handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/spiffy/trunk/spiffy.scm

    r12024 r12025  
    6262(define mime-type-map
    6363  (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)
    6865     ("html" . text/html)
     66     ("xhtml" . text/xhtml+xml)
    6967     ("js"  . text/javascript)
    7068     ("pdf" . application/pdf)
    7169     ("css" . text/css)
    72      ("bmp" . image/bmp)
     70     ("png" . image/png)
    7371     ("ico" . image/x-icon)
    7472     ("gif" . image/gif)
     73     ("jpeg" . image/jpeg)
    7574     ("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))))
    7879(define default-mime-type (make-parameter 'application/octet-stream))
    7980(define default-host (make-parameter "localhost")) ;; XXX Can we do without?
     81(define file-extension-handlers (make-parameter '()))
    8082
    8183;;; Custom handlers
     
    8789  (make-parameter
    8890   (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)))))))
    9397(define handle-not-found
    9498  (make-parameter
     
    97101                  "The resource you requested could not be found"))))
    98102
    99 
    100103;;; Internal parameters
    101104(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)))
    102108
    103109;; A simple utility procedure to render a status code with message
     
    136142          (file-close fd))))))
    137143
    138 (define (extension->mime-type ext)
    139   (alist-ref (or ext "") (mime-type-map) string-ci=? (default-mime-type)))
    140 
    141144(define (with-headers new-headers thunk)
    142145  (parameterize ((current-response
Note: See TracChangeset for help on using the changeset viewer.