0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-diagnostic-channel-http-response-created.js
Marco Ippolito 560b2a1677
http: add diagnostic channel http.server.response.created
PR-URL: https://github.com/nodejs/node/pull/55622
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2024-11-02 13:46:20 +00:00

46 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const dc = require('diagnostics_channel');
const isOutgoingMessage = (object) => object instanceof http.OutgoingMessage;
const isIncomingMessage = (object) => object instanceof http.IncomingMessage;
dc.subscribe('http.server.response.created', common.mustCall(({
request,
response,
}) => {
assert.strictEqual(request.headers.foo, 'bar');
assert.strictEqual(response.getHeader('baz'), undefined);
assert.strictEqual(isIncomingMessage(request), true);
assert.strictEqual(isOutgoingMessage(response), true);
}));
dc.subscribe('http.server.response.finish', common.mustCall(({
request,
response,
}) => {
assert.strictEqual(request.headers.foo, 'bar');
assert.strictEqual(response.getHeader('baz'), 'bar');
assert.strictEqual(isIncomingMessage(request), true);
assert.strictEqual(isOutgoingMessage(response), true);
}));
const server = http.createServer(common.mustCall((_, res) => {
res.setHeader('baz', 'bar');
res.end('done');
}));
server.listen(() => {
const { port } = server.address();
http.get({
port,
headers: {
'foo': 'bar',
}
}, common.mustCall(() => {
server.close();
}));
});