forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: add diagnostic channel
http.client.request.created
PR-URL: nodejs#55586 Fixes: nodejs#55352 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: theanarkh <theratliter@gmail.com>
- Loading branch information
1 parent
16abab2
commit 04bf62d
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/parallel/test-diagnostic-channel-http-request-created.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters