Skip to content

Commit 633644f

Browse files
committedApr 7, 2019
fix: capitalize outgoing headers
1 parent 9a392f1 commit 633644f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed
 

‎packages/sirv/index.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ function is404(res) {
4141
module.exports = function (dir, opts={}) {
4242
dir = resolve(dir || '.');
4343

44-
let notFound = opts.onNoMatch || is404;
45-
let setHeaders = opts.setHeaders || noop;
44+
let isNotFound = opts.onNoMatch || is404;
4645
let extensions = opts.extensions || ['html', 'htm'];
4746

4847
if (opts.dev) {
4948
return function (req, res, next) {
5049
let uri = decodeURIComponent(req.path || req.pathname || parser(req).pathname);
5150
let arr = uri.includes('.') ? [uri] : toAssume(uri, extensions);
5251
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));
5554
fs.createReadStream(file).pipe(res);
5655
}
5756
}
5857

59-
cc && opts.immutable && (cc += ',immutable');
58+
let setHeaders = opts.setHeaders || noop;
6059
let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`;
60+
if (cc && opts.immutable) cc += ',immutable';
6161

6262
opts.cwd = dir;
6363
let abs, stats, headers;
@@ -66,19 +66,19 @@ module.exports = function (dir, opts={}) {
6666
abs = join(dir, str);
6767
stats = fs.statSync(abs);
6868
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()
7272
};
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);
7575
FILES['/' + str.replace(/\\+/g, '/')] = { abs, stats, headers };
7676
});
7777

7878
return function (req, res, next) {
7979
let pathname = decodeURIComponent(req.path || req.pathname || parser(req).pathname);
8080
let data = find(pathname, extensions);
81-
if (!data) return next ? next() : notFound(res);
81+
if (!data) return next ? next() : isNotFound(res);
8282

8383
setHeaders(res, pathname, data.stats);
8484
res.writeHead(200, data.headers);

0 commit comments

Comments
 (0)
Please sign in to comment.