0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/parallel/test-diagnostic-channel-http-request-created.js
Marco Ippolito 4379dfb1fd
http: add diagnostic channel http.client.request.created
PR-URL: https://github.com/nodejs/node/pull/55586
Fixes: https://github.com/nodejs/node/issues/55352
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: theanarkh <theratliter@gmail.com>
2024-10-31 13:04:25 +00:00

40 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 isHTTPServer = (server) => server instanceof http.Server;
const isOutgoingMessage = (object) => object instanceof http.OutgoingMessage;
dc.subscribe('http.client.request.created', common.mustCall(({ request }) => {
assert.strictEqual(request.getHeader('foo'), 'bar');
assert.strictEqual(request.getHeader('baz'), undefined);
assert.strictEqual(isOutgoingMessage(request), true);
assert.strictEqual(isHTTPServer(server), true);
}));
dc.subscribe('http.client.request.start', common.mustCall(({ request }) => {
assert.strictEqual(request.getHeader('foo'), 'bar');
assert.strictEqual(request.getHeader('baz'), 'bar');
assert.strictEqual(isOutgoingMessage(request), true);
}));
const server = http.createServer(common.mustCall((_, res) => {
res.end('done');
}));
server.listen(async () => {
const { port } = server.address();
const req = http.request({
port,
headers: {
'foo': 'bar',
}
}, common.mustCall(() => {
server.close();
}));
req.setHeader('baz', 'bar');
req.end();
});