From c2adb253012864f12b3babfac9882c613f640d52 Mon Sep 17 00:00:00 2001 From: Andrew Hughes Date: Tue, 7 Jan 2020 10:11:11 +0000 Subject: [PATCH 1/2] doc: prefer server vs srv and client vs clt --- doc/api/http.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index 48767107affce5..3ca76cc92a598c 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -374,16 +374,16 @@ const proxy = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('okay'); }); -proxy.on('connect', (req, cltSocket, head) => { +proxy.on('connect', (req, clientSocket, head) => { // Connect to an origin server const { port, hostname } = new URL(`http://${req.url}`); - const srvSocket = net.connect(port || 80, hostname, () => { - cltSocket.write('HTTP/1.1 200 Connection Established\r\n' + + const serverSocket = net.connect(port || 80, hostname, () => { + clientSocket.write('HTTP/1.1 200 Connection Established\r\n' + 'Proxy-agent: Node.js-Proxy\r\n' + '\r\n'); - srvSocket.write(head); - srvSocket.pipe(cltSocket); - cltSocket.pipe(srvSocket); + serverSocket.write(head); + serverSocket.pipe(clientSocket); + clientSocket.pipe(serverSocket); }); }); @@ -525,11 +525,11 @@ A client server pair demonstrating how to listen for the `'upgrade'` event. const http = require('http'); // Create an HTTP server -const srv = http.createServer((req, res) => { +const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('okay'); }); -srv.on('upgrade', (req, socket, head) => { +server.on('upgrade', (req, socket, head) => { socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + 'Upgrade: WebSocket\r\n' + 'Connection: Upgrade\r\n' + @@ -539,7 +539,7 @@ srv.on('upgrade', (req, socket, head) => { }); // Now that server is running -srv.listen(1337, '127.0.0.1', () => { +server.listen(1337, '127.0.0.1', () => { // make a request const options = { From 87c536fc6c36d81d6a6a81f60cb77465769b84b9 Mon Sep 17 00:00:00 2001 From: Andrew Hughes Date: Tue, 7 Jan 2020 10:21:19 +0000 Subject: [PATCH 2/2] test: prefer server over srv --- test/parallel/test-http-server-multiheaders.js | 6 +++--- test/parallel/test-http-server-multiheaders2.js | 6 +++--- test/parallel/test-http-upgrade-agent.js | 6 +++--- test/parallel/test-http-upgrade-client.js | 6 +++--- test/parallel/test-net-error-twice.js | 4 ++-- test/parallel/test-net-server-listen-path.js | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/parallel/test-http-server-multiheaders.js b/test/parallel/test-http-server-multiheaders.js index bf918ad24cc168..8f633fdb998970 100644 --- a/test/parallel/test-http-server-multiheaders.js +++ b/test/parallel/test-http-server-multiheaders.js @@ -28,7 +28,7 @@ require('../common'); const assert = require('assert'); const http = require('http'); -const srv = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { assert.strictEqual(req.headers.accept, 'abc, def, ghijklmnopqrst'); assert.strictEqual(req.headers.host, 'foo'); assert.strictEqual(req.headers['www-authenticate'], 'foo, bar, baz'); @@ -43,10 +43,10 @@ const srv = http.createServer(function(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('EOF'); - srv.close(); + server.close(); }); -srv.listen(0, function() { +server.listen(0, function() { http.get({ host: 'localhost', port: this.address().port, diff --git a/test/parallel/test-http-server-multiheaders2.js b/test/parallel/test-http-server-multiheaders2.js index 95ee5b61fa916d..1e19708557ef24 100644 --- a/test/parallel/test-http-server-multiheaders2.js +++ b/test/parallel/test-http-server-multiheaders2.js @@ -69,7 +69,7 @@ const multipleForbidden = [ // 'Content-Length', ]; -const srv = http.createServer(function(req, res) { +const server = http.createServer(function(req, res) { multipleForbidden.forEach(function(header) { assert.strictEqual(req.headers[header.toLowerCase()], 'foo', `header parsed incorrectly: ${header}`); @@ -83,7 +83,7 @@ const srv = http.createServer(function(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('EOF'); - srv.close(); + server.close(); }); function makeHeader(value) { @@ -98,7 +98,7 @@ const headers = [] .concat(multipleAllowed.map(makeHeader('bar'))) .concat(multipleForbidden.map(makeHeader('bar'))); -srv.listen(0, function() { +server.listen(0, function() { http.get({ host: 'localhost', port: this.address().port, diff --git a/test/parallel/test-http-upgrade-agent.js b/test/parallel/test-http-upgrade-agent.js index 5c840eeb532814..cb33edc32e0139 100644 --- a/test/parallel/test-http-upgrade-agent.js +++ b/test/parallel/test-http-upgrade-agent.js @@ -31,7 +31,7 @@ const http = require('http'); const net = require('net'); // Create a TCP server -const srv = net.createServer(function(c) { +const server = net.createServer(function(c) { c.on('data', function(d) { c.write('HTTP/1.1 101\r\n'); c.write('hello: world\r\n'); @@ -46,7 +46,7 @@ const srv = net.createServer(function(c) { }); }); -srv.listen(0, '127.0.0.1', common.mustCall(function() { +server.listen(0, '127.0.0.1', common.mustCall(function() { const options = { port: this.address().port, @@ -82,7 +82,7 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() { req.on('close', common.mustCall(function() { socket.end(); - srv.close(); + server.close(); })); })); })); diff --git a/test/parallel/test-http-upgrade-client.js b/test/parallel/test-http-upgrade-client.js index d18ac273d6dab1..8fe756f469f09a 100644 --- a/test/parallel/test-http-upgrade-client.js +++ b/test/parallel/test-http-upgrade-client.js @@ -34,7 +34,7 @@ const Countdown = require('../common/countdown'); const expectedRecvData = 'nurtzo'; // Create a TCP server -const srv = net.createServer(function(c) { +const server = net.createServer(function(c) { c.on('data', function(d) { c.write('HTTP/1.1 101\r\n'); c.write('hello: world\r\n'); @@ -49,7 +49,7 @@ const srv = net.createServer(function(c) { }); }); -srv.listen(0, '127.0.0.1', common.mustCall(function() { +server.listen(0, '127.0.0.1', common.mustCall(function() { const port = this.address().port; const headers = [ { @@ -63,7 +63,7 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() { ['Origin', 'http://www.websocket.org'] ] ]; - const countdown = new Countdown(headers.length, () => srv.close()); + const countdown = new Countdown(headers.length, () => server.close()); headers.forEach(function(h) { const req = http.get({ diff --git a/test/parallel/test-net-error-twice.js b/test/parallel/test-net-error-twice.js index 4c2839d372fcb4..b26b825d16c15f 100644 --- a/test/parallel/test-net-error-twice.js +++ b/test/parallel/test-net-error-twice.js @@ -37,14 +37,14 @@ function ready() { } } -const srv = net.createServer(function onConnection(conn) { +const server = net.createServer(function onConnection(conn) { conn.on('error', function(err) { errs.push(err); if (errs.length > 1 && errs[0] === errs[1]) assert.fail('Should not emit the same error twice'); }); conn.on('close', function() { - srv.unref(); + server.unref(); }); serverSocket = conn; ready(); diff --git a/test/parallel/test-net-server-listen-path.js b/test/parallel/test-net-server-listen-path.js index cc7c6678b04224..99144ceb494a64 100644 --- a/test/parallel/test-net-server-listen-path.js +++ b/test/parallel/test-net-server-listen-path.js @@ -55,7 +55,7 @@ function randomPipePath() { { const handlePath = randomPipePath(); - const srv = net.createServer() + const server = net.createServer() .listen({ path: handlePath, readableAll: true, @@ -66,24 +66,24 @@ function randomPipePath() { assert.notStrictEqual(mode & fs.constants.S_IROTH, 0); assert.notStrictEqual(mode & fs.constants.S_IWOTH, 0); } - srv.close(); + server.close(); })); } // Test should emit "error" events when listening fails. { const handlePath = randomPipePath(); - const srv1 = net.createServer().listen({ path: handlePath }, () => { + const server1 = net.createServer().listen({ path: handlePath }, () => { // As the handlePath is in use, binding to the same address again should // make the server emit an 'EADDRINUSE' error. - const srv2 = net.createServer() + const server2 = net.createServer() .listen({ path: handlePath, writableAll: true, }, common.mustNotCall()); - srv2.on('error', common.mustCall((err) => { - srv1.close(); + server2.on('error', common.mustCall((err) => { + server1.close(); assert.strictEqual(err.code, 'EADDRINUSE'); assert(/^listen EADDRINUSE: address already in use/.test(err.message)); }));