@@ -41,23 +41,23 @@ function is404(res) {
41
41
module . exports = function ( dir , opts = { } ) {
42
42
dir = resolve ( dir || '.' ) ;
43
43
44
- let notFound = opts . onNoMatch || is404 ;
45
- let setHeaders = opts . setHeaders || noop ;
44
+ let isNotFound = opts . onNoMatch || is404 ;
46
45
let extensions = opts . extensions || [ 'html' , 'htm' ] ;
47
46
48
47
if ( opts . dev ) {
49
48
return function ( req , res , next ) {
50
49
let uri = decodeURIComponent ( req . path || req . pathname || parser ( req ) . pathname ) ;
51
50
let arr = uri . includes ( '.' ) ? [ uri ] : toAssume ( uri , extensions ) ;
52
51
let file = arr . map ( x => join ( dir , x ) ) . find ( fs . existsSync ) ;
53
- if ( ! file ) return next ? next ( ) : notFound ( res ) ;
54
- res . setHeader ( 'content-type ' , mime . getType ( file ) ) ;
52
+ if ( ! file ) return next ? next ( ) : isNotFound ( res ) ;
53
+ res . setHeader ( 'Content-Type ' , mime . getType ( file ) ) ;
55
54
fs . createReadStream ( file ) . pipe ( res ) ;
56
55
}
57
56
}
58
57
59
- cc && opts . immutable && ( cc += ',immutable' ) ;
58
+ let setHeaders = opts . setHeaders || noop ;
60
59
let cc = opts . maxAge != null && `public,max-age=${ opts . maxAge } ` ;
60
+ if ( cc && opts . immutable ) cc += ',immutable' ;
61
61
62
62
opts . cwd = dir ;
63
63
let abs , stats , headers ;
@@ -66,19 +66,19 @@ module.exports = function (dir, opts={}) {
66
66
abs = join ( dir , str ) ;
67
67
stats = fs . statSync ( abs ) ;
68
68
headers = {
69
- 'content-length ' : stats . size ,
70
- 'content-type ' : mime . getType ( str ) ,
71
- 'last-modified ' : stats . mtime . toUTCString ( )
69
+ 'Content-Length ' : stats . size ,
70
+ 'Content-Type ' : mime . getType ( str ) ,
71
+ 'Last-Modified ' : stats . mtime . toUTCString ( )
72
72
} ;
73
- cc && ( headers [ 'cache-control ' ] = cc ) ;
74
- opts . etag && ( headers [ 'etag ' ] = toEtag ( stats ) ) ;
73
+ if ( cc ) headers [ 'Cache-Control ' ] = cc ;
74
+ if ( opts . etag ) headers [ 'ETag ' ] = toEtag ( stats ) ;
75
75
FILES [ '/' + str . replace ( / \\ + / g, '/' ) ] = { abs, stats, headers } ;
76
76
} ) ;
77
77
78
78
return function ( req , res , next ) {
79
79
let pathname = decodeURIComponent ( req . path || req . pathname || parser ( req ) . pathname ) ;
80
80
let data = find ( pathname , extensions ) ;
81
- if ( ! data ) return next ? next ( ) : notFound ( res ) ;
81
+ if ( ! data ) return next ? next ( ) : isNotFound ( res ) ;
82
82
83
83
setHeaders ( res , pathname , data . stats ) ;
84
84
res . writeHead ( 200 , data . headers ) ;
0 commit comments