Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: prefer server over srv #31224

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, notice the obiquitous use use TLAs in the HTTP API.

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' +
Expand All @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http-server-multiheaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http-server-multiheaders2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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) {
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http-upgrade-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -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();
}));
}));
}));
6 changes: 3 additions & 3 deletions test/parallel/test-http-upgrade-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 = [
{
Expand All @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-error-twice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-net-server-listen-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function randomPipePath() {
{
const handlePath = randomPipePath();

const srv = net.createServer()
const server = net.createServer()
.listen({
path: handlePath,
readableAll: true,
Expand All @@ -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));
}));
Expand Down