Skip to content

Commit 83731c5

Browse files
committed
send-type: cast toLowerCase before juggling;
Closes #57
1 parent a4d96b9 commit 83731c5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/send-type/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
const { STATUS_CODES } = require('http');
22

3-
const TYPE = 'Content-Type';
3+
const TYPE = 'content-type';
44
const OSTREAM = 'application/octet-stream';
55

66
module.exports = function (res, code=200, data='', headers={}) {
7-
let type = headers[TYPE];
7+
let k, obj={};
8+
for (k in headers) {
9+
obj[k.toLowerCase()] = headers[k];
10+
}
11+
12+
let type = obj[TYPE];
813

914
if (!!data && typeof data.pipe === 'function') {
1015
res.setHeader(TYPE, type || OSTREAM);
@@ -20,9 +25,9 @@ module.exports = function (res, code=200, data='', headers={}) {
2025
data = data || STATUS_CODES[code];
2126
}
2227

23-
headers[TYPE] = type || 'text/plain';
24-
headers['Content-Length'] = Buffer.byteLength(data);
28+
obj[TYPE] = type || 'text/plain';
29+
obj['content-length'] = Buffer.byteLength(data);
2530

26-
res.writeHead(code, headers);
31+
res.writeHead(code, obj);
2732
res.end(data);
2833
}

0 commit comments

Comments
 (0)