-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: add diagnostics channel for http client
- Loading branch information
Showing
3 changed files
with
174 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
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,57 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
const dc = require('diagnostics_channel'); | ||
|
||
const onClientRequestStart = dc.channel('http.client.request.start'); | ||
const onClientResponseFinish = dc.channel('http.client.response.finish'); | ||
const onServerRequestStart = dc.channel('http.server.request.start'); | ||
const onServerResponseFinish = dc.channel('http.server.response.finish'); | ||
|
||
onClientRequestStart.subscribe(common.mustCall(({ request }) => { | ||
assert.strictEqual(typeof request, 'object'); | ||
})); | ||
|
||
onClientResponseFinish.subscribe(common.mustCall(({ request, response }) => { | ||
assert.strictEqual(typeof request, 'object'); | ||
assert.strictEqual(typeof response, 'object'); | ||
})); | ||
|
||
onServerRequestStart.subscribe(common.mustCall(({ | ||
request, | ||
response, | ||
socket, | ||
server, | ||
}) => { | ||
assert.strictEqual(typeof request, 'object'); | ||
assert.strictEqual(typeof response, 'object'); | ||
assert.strictEqual(typeof socket, 'object'); | ||
assert.strictEqual(typeof server, 'object'); | ||
})); | ||
|
||
onServerResponseFinish.subscribe(common.mustCall(({ | ||
request, | ||
response, | ||
socket, | ||
server, | ||
}) => { | ||
assert.strictEqual(typeof request, 'object'); | ||
assert.strictEqual(typeof response, 'object'); | ||
assert.strictEqual(typeof socket, 'object'); | ||
assert.strictEqual(typeof server, 'object'); | ||
})); | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
res.end('done'); | ||
})); | ||
|
||
server.listen(() => { | ||
const { port } = server.address(); | ||
http.get(`http://localhost:${port}`, (res) => { | ||
res.resume(); | ||
res.on('end', () => { | ||
server.close(); | ||
}); | ||
}); | ||
}); |