| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 41ea42b commit 121c547
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,21 +6,18 @@ const dc = require('diagnostics_channel'); | |||
| 6 | 6 | const assert = require('assert'); | |
| 7 | 7 | const http = require('http'); | |
| 8 | 8 | ||
| 9 | - const incomingStartChannel = dc.channel('http.server.request.start'); | ||
| 10 | - const outgoingFinishChannel = dc.channel('http.server.response.finish'); | ||
| 11 | - | ||
| 12 | 9 | const als = new AsyncLocalStorage(); | |
| 13 | 10 | let context; | |
| 14 | 11 | ||
| 15 | 12 | // Bind requests to an AsyncLocalStorage context | |
| 16 | - incomingStartChannel.subscribe(common.mustCall((message) => { | ||
| 13 | + dc.subscribe('http.server.request.start', common.mustCall((message) => { | ||
| 17 | 14 | als.enterWith(message); | |
| 18 | 15 | context = message; | |
| 19 | 16 | })); | |
| 20 | 17 | ||
| 21 | 18 | // When the request ends, verify the context has been maintained | |
| 22 | 19 | // and that the messages contain the expected data | |
| 23 | - outgoingFinishChannel.subscribe(common.mustCall((message) => { | ||
| 20 | + dc.subscribe('http.server.response.finish', common.mustCall((message) => { | ||
| 24 | 21 | const data = { | |
| 25 | 22 | request, | |
| 26 | 23 | response, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,26 +5,24 @@ const http = require('http'); | |||
| 5 | 5 | const net = require('net'); | |
| 6 | 6 | const dc = require('diagnostics_channel'); | |
| 7 | 7 | ||
| 8 | - const onClientRequestStart = dc.channel('http.client.request.start'); | ||
| 9 | - const onClientResponseFinish = dc.channel('http.client.response.finish'); | ||
| 10 | - const onServerRequestStart = dc.channel('http.server.request.start'); | ||
| 11 | - const onServerResponseFinish = dc.channel('http.server.response.finish'); | ||
| 12 | - | ||
| 13 | 8 | const isHTTPServer = (server) => server instanceof http.Server; | |
| 14 | 9 | const isIncomingMessage = (object) => object instanceof http.IncomingMessage; | |
| 15 | 10 | const isOutgoingMessage = (object) => object instanceof http.OutgoingMessage; | |
| 16 | 11 | const isNetSocket = (socket) => socket instanceof net.Socket; | |
| 17 | 12 | ||
| 18 | - onClientRequestStart.subscribe(common.mustCall(({ request }) => { | ||
| 13 | + dc.subscribe('http.client.request.start', common.mustCall(({ request }) => { | ||
| 19 | 14 | assert.strictEqual(isOutgoingMessage(request), true); | |
| 20 | 15 | })); | |
| 21 | 16 | ||
| 22 | - onClientResponseFinish.subscribe(common.mustCall(({ request, response }) => { | ||
| 17 | + dc.subscribe('http.client.response.finish', common.mustCall(({ | ||
| 18 | + request, | ||
| 19 | + response | ||
| 20 | + }) => { | ||
| 23 | 21 | assert.strictEqual(isOutgoingMessage(request), true); | |
| 24 | 22 | assert.strictEqual(isIncomingMessage(response), true); | |
| 25 | 23 | })); | |
| 26 | 24 | ||
| 27 | - onServerRequestStart.subscribe(common.mustCall(({ | ||
| 25 | + dc.subscribe('http.server.request.start', common.mustCall(({ | ||
| 28 | 26 | request, | |
| 29 | 27 | response, | |
| 30 | 28 | socket, | |
@@ -36,7 +34,7 @@ onServerRequestStart.subscribe(common.mustCall(({ | |||
| 36 | 34 | assert.strictEqual(isHTTPServer(server), true); | |
| 37 | 35 | })); | |
| 38 | 36 | ||
| 39 | - onServerResponseFinish.subscribe(common.mustCall(({ | ||
| 37 | + dc.subscribe('http.server.response.finish', common.mustCall(({ | ||
| 40 | 38 | request, | |
| 41 | 39 | response, | |
| 42 | 40 | socket, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments