mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
560b2a1677
PR-URL: https://github.com/nodejs/node/pull/55622 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const { addresses } = require('../common/internet');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const net = require('net');
|
|
const dc = require('diagnostics_channel');
|
|
|
|
const isHTTPServer = (server) => server instanceof http.Server;
|
|
const isIncomingMessage = (object) => object instanceof http.IncomingMessage;
|
|
const isOutgoingMessage = (object) => object instanceof http.OutgoingMessage;
|
|
const isNetSocket = (socket) => socket instanceof net.Socket;
|
|
const isError = (error) => error instanceof Error;
|
|
|
|
dc.subscribe('http.client.request.start', common.mustCall(({ request }) => {
|
|
assert.strictEqual(isOutgoingMessage(request), true);
|
|
}, 2));
|
|
|
|
dc.subscribe('http.client.request.error', common.mustCall(({ request, error }) => {
|
|
assert.strictEqual(isOutgoingMessage(request), true);
|
|
assert.strictEqual(isError(error), true);
|
|
}));
|
|
|
|
dc.subscribe('http.client.response.finish', common.mustCall(({
|
|
request,
|
|
response
|
|
}) => {
|
|
assert.strictEqual(isOutgoingMessage(request), true);
|
|
assert.strictEqual(isIncomingMessage(response), true);
|
|
}));
|
|
|
|
dc.subscribe('http.server.request.start', common.mustCall(({
|
|
request,
|
|
response,
|
|
socket,
|
|
server,
|
|
}) => {
|
|
assert.strictEqual(isIncomingMessage(request), true);
|
|
assert.strictEqual(isOutgoingMessage(response), true);
|
|
assert.strictEqual(isNetSocket(socket), true);
|
|
assert.strictEqual(isHTTPServer(server), true);
|
|
}));
|
|
|
|
dc.subscribe('http.server.response.finish', common.mustCall(({
|
|
request,
|
|
response,
|
|
socket,
|
|
server,
|
|
}) => {
|
|
assert.strictEqual(isIncomingMessage(request), true);
|
|
assert.strictEqual(isOutgoingMessage(response), true);
|
|
assert.strictEqual(isNetSocket(socket), true);
|
|
assert.strictEqual(isHTTPServer(server), true);
|
|
}));
|
|
|
|
dc.subscribe('http.server.response.created', common.mustCall(({
|
|
request,
|
|
response,
|
|
}) => {
|
|
assert.strictEqual(isIncomingMessage(request), true);
|
|
assert.strictEqual(isOutgoingMessage(response), true);
|
|
}));
|
|
|
|
dc.subscribe('http.client.request.created', common.mustCall(({ request }) => {
|
|
assert.strictEqual(isOutgoingMessage(request), true);
|
|
assert.strictEqual(isHTTPServer(server), true);
|
|
}, 2));
|
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
res.end('done');
|
|
}));
|
|
|
|
server.listen(async () => {
|
|
const { port } = server.address();
|
|
const invalidRequest = http.get({
|
|
host: addresses.INVALID_HOST,
|
|
});
|
|
await new Promise((resolve) => {
|
|
invalidRequest.on('error', resolve);
|
|
});
|
|
http.get(`http://localhost:${port}`, (res) => {
|
|
res.resume();
|
|
res.on('end', () => {
|
|
server.close();
|
|
});
|
|
});
|
|
});
|