mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 06:38:13 +00:00

There has been occasional nits for spacing in object literals in PRs but the project does not lint for it and it is not always handled consistently in the existing code, even on adjacent lines of a file. This change enables a linting rule requiring no space between the key and the colon, and requiring at least one space (but allowing for more so property values can be lined up if desired) between the colon and the value. This appears to be the most common style used in the current code base. Example code the complies with lint rule: myObj = { foo: 'bar' }; Examples that do not comply with the lint rule: myObj = { foo : 'bar' }; myObj = { foo:'bar' }; PR-URL: https://github.com/nodejs/node/pull/6592 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const http = require('http');
|
|
const assert = require('assert');
|
|
|
|
// Test that certain response header fields do not repeat.
|
|
// 'content-length' should also be in this list but it is
|
|
// handled differently because multiple content-lengths are
|
|
// an error (see test-http-response-multi-content-length.js).
|
|
const norepeat = [
|
|
'content-type',
|
|
'user-agent',
|
|
'referer',
|
|
'host',
|
|
'authorization',
|
|
'proxy-authorization',
|
|
'if-modified-since',
|
|
'if-unmodified-since',
|
|
'from',
|
|
'location',
|
|
'max-forwards',
|
|
'retry-after',
|
|
'etag',
|
|
'last-modified',
|
|
'server',
|
|
'age',
|
|
'expires'
|
|
];
|
|
|
|
const server = http.createServer(function(req, res) {
|
|
var num = req.headers['x-num'];
|
|
if (num == 1) {
|
|
for (const name of norepeat) {
|
|
res.setHeader(name, ['A', 'B']);
|
|
}
|
|
res.setHeader('X-A', ['A', 'B']);
|
|
} else if (num == 2) {
|
|
const headers = {};
|
|
for (const name of norepeat) {
|
|
headers[name] = ['A', 'B'];
|
|
}
|
|
headers['X-A'] = ['A', 'B'];
|
|
res.writeHead(200, headers);
|
|
}
|
|
res.end('ok');
|
|
});
|
|
|
|
server.listen(common.PORT, common.mustCall(function() {
|
|
var count = 0;
|
|
for (let n = 1; n <= 2 ; n++) {
|
|
// this runs twice, the first time, the server will use
|
|
// setHeader, the second time it uses writeHead. The
|
|
// result on the client side should be the same in
|
|
// either case -- only the first instance of the header
|
|
// value should be reported for the header fields listed
|
|
// in the norepeat array.
|
|
http.get(
|
|
{port: common.PORT, headers: {'x-num': n}},
|
|
common.mustCall(function(res) {
|
|
if (++count === 2) server.close();
|
|
for (const name of norepeat) {
|
|
assert.equal(res.headers[name], 'A');
|
|
}
|
|
assert.equal(res.headers['x-a'], 'A, B');
|
|
})
|
|
);
|
|
}
|
|
}));
|