Changeset 15316 in project


Ignore:
Timestamp:
08/04/09 17:02:01 (10 years ago)
Author:
sjamaan
Message:

Handle file access denied errors by sending a 403 Forbidden when the file cannot be opened

File:
1 edited

Legend:

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

    r15312 r15316  
    245245
    246246(define (send-static-file filename)
    247   (let ((path (make-pathname (root-path) filename)))
    248     (with-headers `((content-length ,(file-size path))
    249                     (content-type ,(extension->mime-type
    250                                     (pathname-extension filename))))
    251       (lambda ()
    252         (write-logged-response)
    253         (let ((fd (file-open path (+ open/binary open/rdonly))))
    254           (handle-exceptions exn (begin
    255                                    (file-close fd)
    256                                    (signal exn))
    257                              (sendfile fd (response-port (current-response))))
    258           (file-close fd))))))
     247  (condition-case
     248      (let* ((path (make-pathname (root-path) filename))
     249             (fd (file-open path (+ open/binary open/rdonly))))
     250        (with-headers `((content-length ,(file-size path))
     251                        (content-type ,(extension->mime-type
     252                                        (pathname-extension filename))))
     253          (lambda ()
     254            (write-logged-response)
     255            (handle-exceptions exn (begin
     256                                     (file-close fd)
     257                                     (signal exn))
     258                               (sendfile fd (response-port (current-response))))
     259            (file-close fd))))
     260    ((exn i/o file) (send-status 403 "Forbidden"))))
    259261
    260262(define (with-headers new-headers thunk)
Note: See TracChangeset for help on using the changeset viewer.