* revise requires to scheme/*
* use `for' and better use of regexp patterns in `match' * use a literal byte-regexp in `make-path->mime-type' and use it throught `match' * delay reading of the mime types table (since there are uses like serve/servlet that will never use it anyway) svn: r12527
This commit is contained in:
parent
9405d57292
commit
8b5b87c807
|
@ -1,7 +1,7 @@
|
||||||
#lang scheme/base
|
#lang scheme/base
|
||||||
(require mzlib/contract
|
(require scheme/contract
|
||||||
mzlib/plt-match
|
scheme/match
|
||||||
mzlib/string)
|
scheme/promise)
|
||||||
(require "util.ss"
|
(require "util.ss"
|
||||||
web-server/http)
|
web-server/http)
|
||||||
(provide/contract
|
(provide/contract
|
||||||
|
@ -17,13 +17,9 @@
|
||||||
(match (read-line (current-input-port) 'any)
|
(match (read-line (current-input-port) 'any)
|
||||||
[(? eof-object?)
|
[(? eof-object?)
|
||||||
(void)]
|
(void)]
|
||||||
[(regexp #"^([^\t ]+)[\t ]+(.+)$"
|
[(regexp #rx#"^([^\t ]+)[\t ]+(.+)$" (list _ type exts))
|
||||||
(list s type exts))
|
(for ([ext (in-list (regexp-split #" " exts))])
|
||||||
(for-each (lambda (ext)
|
(hash-set! MIME-TYPE-TABLE (lowercase-symbol! ext) type))
|
||||||
(hash-set! MIME-TYPE-TABLE
|
|
||||||
(lowercase-symbol! ext)
|
|
||||||
type))
|
|
||||||
(regexp-split #" " exts))
|
|
||||||
(loop)]
|
(loop)]
|
||||||
[_
|
[_
|
||||||
(loop)]))))
|
(loop)]))))
|
||||||
|
@ -36,12 +32,11 @@
|
||||||
;; 1. Can we determine the mime type based on file contents?
|
;; 1. Can we determine the mime type based on file contents?
|
||||||
;; 2. Assuming that 7-bit ASCII is correct for mime-type
|
;; 2. Assuming that 7-bit ASCII is correct for mime-type
|
||||||
(define (make-path->mime-type a-path)
|
(define (make-path->mime-type a-path)
|
||||||
(define MIME-TYPE-TABLE (read-mime-types a-path))
|
(define MIME-TYPE-TABLE (delay (read-mime-types a-path)))
|
||||||
(define file-suffix-regexp (byte-regexp #".*\\.([^\\.]*$)"))
|
|
||||||
(lambda (path)
|
(lambda (path)
|
||||||
(match (regexp-match file-suffix-regexp (path->bytes path))
|
(match (path->bytes path)
|
||||||
[(list path-bytes sffx)
|
[(regexp #rx#".*\\.([^\\.]*$)" (list _ sffx))
|
||||||
(hash-ref MIME-TYPE-TABLE
|
(hash-ref (force MIME-TYPE-TABLE)
|
||||||
(lowercase-symbol! sffx)
|
(lowercase-symbol! sffx)
|
||||||
(lambda () TEXT/HTML-MIME-TYPE))]
|
TEXT/HTML-MIME-TYPE)]
|
||||||
[_ TEXT/HTML-MIME-TYPE])))
|
[_ TEXT/HTML-MIME-TYPE])))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user