Changeset 26191 in project


Ignore:
Timestamp:
03/17/12 16:23:50 (10 years ago)
Author:
sjamaan
Message:

spiffy: forgot to commit the actual code (not just tests) with r26184

File:
1 edited

Legend:

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

    r25862 r26191  
    124124   (lambda (path)
    125125     (send-status 'forbidden))))
     126;; TODO: maybe simplify this so it falls into more reusable pieces
    126127(define handle-file
    127128  (make-parameter
     
    129130     (let* ((ext (pathname-extension path))
    130131            (h (file-extension-handlers))
     132            (m '(HEAD GET))
    131133            (handler (or (and ext (alist-ref ext h string-ci=?))
    132                          send-static-file)))
     134                         (lambda (fn)
     135                           ;; Check here for allowed methods, because
     136                           ;; for example a .cgi handler might allow POST,
     137                           ;; and anyone can re-use send-static-file to
     138                           ;; send a file even when another method is used.
     139                           (if (not (memq (request-method (current-request)) m))
     140                               (with-headers `((allow . ,m))
     141                                 (lambda () (send-status 'method-not-allowed)))
     142                               (send-static-file fn))))))
    133143       (handler path)))))
    134144(define handle-not-found
     
    325335                  (write-logged-response)
    326336                  (unless (eq? 'HEAD (request-method (current-request)))
    327                     (call-with-input-file* path
    328                       (lambda (f)
    329                         (sendfile f (response-port (current-response)))))))))))
     337                    (call-with-input-file*
     338                     path (lambda (f)
     339                            (sendfile f (response-port (current-response)))))))))))
    330340    ((exn i/o file) (send-status 'forbidden))))
    331341
Note: See TracChangeset for help on using the changeset viewer.