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.server.response.created
PR-URL: nodejs#55622 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
- Loading branch information
1 parent
b49aaf5
commit aac57f2
Showing
4 changed files
with
68 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
45 changes: 45 additions & 0 deletions
45
test/parallel/test-diagnostic-channel-http-response-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,45 @@ | ||
'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(); | ||
})); | ||
}); |
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