mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-12-06 04:56:15 +08:00
Publish HTTP server diagnostics channels (#4647)
* Publish HTTP server diagnostics channels * http: keep the response's socket through the finish-channel publish
This commit is contained in:
@@ -14792,9 +14792,9 @@
|
||||
"inherited": true
|
||||
},
|
||||
"static": {
|
||||
"status": "not-implemented",
|
||||
"detail": "No static compiler lowering is registered for this API yet.",
|
||||
"verification": "registry-gap"
|
||||
"status": "supported",
|
||||
"detail": "Implemented for the documented scriptc module-loader subset.",
|
||||
"verification": "test-backed"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -14815,9 +14815,9 @@
|
||||
"inherited": true
|
||||
},
|
||||
"static": {
|
||||
"status": "not-implemented",
|
||||
"detail": "No static compiler lowering is registered for this API yet.",
|
||||
"verification": "registry-gap"
|
||||
"status": "supported",
|
||||
"detail": "Implemented for the documented scriptc module-loader subset.",
|
||||
"verification": "test-backed"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -14838,9 +14838,9 @@
|
||||
"inherited": true
|
||||
},
|
||||
"static": {
|
||||
"status": "not-implemented",
|
||||
"detail": "No static compiler lowering is registered for this API yet.",
|
||||
"verification": "registry-gap"
|
||||
"status": "supported",
|
||||
"detail": "Implemented for the documented scriptc module-loader subset.",
|
||||
"verification": "test-backed"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -30661,7 +30661,8 @@
|
||||
"tests/corpus/diagnostics-channel-console-instance.cjs",
|
||||
"tests/corpus/diagnostics-channel-console.cjs",
|
||||
"tests/corpus/diagnostics-channel-store-mutation.cjs",
|
||||
"tests/corpus/diagnostics-channel-store-order.cjs"
|
||||
"tests/corpus/diagnostics-channel-store-order.cjs",
|
||||
"tests/corpus/http-server-diagnostics-channels.ts"
|
||||
]
|
||||
},
|
||||
"anchorSource": "chapter"
|
||||
@@ -31375,8 +31376,11 @@
|
||||
"inherited": true
|
||||
},
|
||||
"static": {
|
||||
"status": "not-implemented",
|
||||
"evidence": "compiler-unmatched:diagnostics_channel"
|
||||
"status": "supported",
|
||||
"evidence": "compiler-feature:diagnostics_channel.'http.server.request.start'",
|
||||
"tests": [
|
||||
"tests/corpus/http-server-diagnostics-channels.ts"
|
||||
]
|
||||
},
|
||||
"anchorSource": "exact"
|
||||
},
|
||||
@@ -31398,8 +31402,11 @@
|
||||
"inherited": true
|
||||
},
|
||||
"static": {
|
||||
"status": "not-implemented",
|
||||
"evidence": "compiler-unmatched:diagnostics_channel"
|
||||
"status": "supported",
|
||||
"evidence": "compiler-feature:diagnostics_channel.'http.server.response.created'",
|
||||
"tests": [
|
||||
"tests/corpus/http-server-diagnostics-channels.ts"
|
||||
]
|
||||
},
|
||||
"anchorSource": "exact"
|
||||
},
|
||||
@@ -31421,8 +31428,11 @@
|
||||
"inherited": true
|
||||
},
|
||||
"static": {
|
||||
"status": "not-implemented",
|
||||
"evidence": "compiler-unmatched:diagnostics_channel"
|
||||
"status": "supported",
|
||||
"evidence": "compiler-feature:diagnostics_channel.'http.server.response.finish'",
|
||||
"tests": [
|
||||
"tests/corpus/http-server-diagnostics-channels.ts"
|
||||
]
|
||||
},
|
||||
"anchorSource": "exact"
|
||||
},
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
{ "chapter": "diagnostics_channel", "symbols": ["channel.bindStore", "channel.unbindStore", "channel.runStores"], "status": "partial", "evidence": ["tests/corpus/2214-dc-bind-store.cjs", "tests/corpus/diagnostics-channel-store-order.cjs", "tests/corpus/diagnostics-channel-store-mutation.cjs", "tests/corpus/diagnostics-channel-audit.cjs"], "reason": "The bound store must be an AsyncLocalStorage instance (the lowering keys bindings by its handle); Node keys a binding by any value the program passes." },
|
||||
{ "chapter": "diagnostics_channel", "signatures": ["`start(event)`", "`end(event)`", "`asyncStart(event)`", "`asyncEnd(event)`", "`error(event)`"], "status": "supported", "evidence": ["tests/corpus/2160-dc-tracing-channel.cjs", "tests/corpus/2211-dc-trace-promise.cjs", "tests/corpus/diagnostics-channel-audit.cjs"] },
|
||||
{ "chapter": "diagnostics_channel", "signatures": ["Event: `'console.log'`", "Event: `'console.info'`", "Event: `'console.debug'`", "Event: `'console.warn'`", "Event: `'console.error'`"], "status": "supported", "evidence": ["tests/corpus/diagnostics-channel-console.cjs", "tests/corpus/diagnostics-channel-console-instance.cjs"], "reason": "A call to a global console output member, a Console instance's output method, the console object called as a value and a method held as a separate function value publish the call's own argument array on the matching channel before the line is written, when the channel has subscribers; every argument type crosses, including a spread's elements, because node:console's output is util.format over that same array." },
|
||||
{ "chapter": "diagnostics_channel", "signatures": ["Event: `'tracing:module.require:start'`", "Event: `'tracing:module.require:end'`", "Event: `'tracing:module.require:error'`", "Event: `'tracing:module.import:asyncStart'`", "Event: `'tracing:module.import:asyncEnd'`", "Event: `'tracing:module.import:error'`"], "status": "not-implemented", "reason": "Node emits these around each CommonJS require() and ESM import() call from its module loaders. A compiled program resolves statically linked modules at compile time: there is no per-call load at run time to trace, and emitting the events would mean instrumenting every require and import site in the module lowering, with the loader's id and parentFilename context. That is module-loader work, not diagnostics_channel work." }
|
||||
{ "chapter": "diagnostics_channel", "signatures": ["Event: `'tracing:module.require:start'`", "Event: `'tracing:module.require:end'`", "Event: `'tracing:module.require:error'`", "Event: `'tracing:module.import:asyncStart'`", "Event: `'tracing:module.import:asyncEnd'`", "Event: `'tracing:module.import:error'`"], "status": "not-implemented", "reason": "Node emits these around each CommonJS require() and ESM import() call from its module loaders. A compiled program resolves statically linked modules at compile time: there is no per-call load at run time to trace, and emitting the events would mean instrumenting every require and import site in the module lowering, with the loader's id and parentFilename context. That is module-loader work, not diagnostics_channel work." },
|
||||
{ "chapter": "diagnostics_channel", "signatures": ["Event: `'http.server.request.start'`", "Event: `'http.server.response.created'`", "Event: `'http.server.response.finish'`"], "status": "supported", "evidence": ["tests/corpus/http-server-diagnostics-channels.ts"], "reason": "An HTTP/1 server publishes Node's three server events when the channel has subscribers: {request, response} on response.created as the response is constructed and {request, response, socket, server} on request.start just after it, both before the 'request' listeners and before the maxRequestsPerSocket and Expect decisions (a request the server answers with its own 417 still publishes them), then {request, response, socket, server} on response.finish from the server's own 'finish' listener, ahead of any the program added. request, response, socket and server are the objects the program holds, so they compare equal; CONNECT and Upgrade requests take the socket without a response and publish none, and the HTTP/2 compatibility layer's responses are not ServerResponses in Node and publish none here. The one shape that stays outside: a request the runtime answers itself for a missing Host header is refused at the connection level before a response exists, where Node constructs the response (publishing all three) and then sends its 400." }
|
||||
]
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"order": [
|
||||
"<repo>/tests/corpus/http-server-diagnostics-channels.ts"
|
||||
],
|
||||
"diags": []
|
||||
}
|
||||
@@ -1664,6 +1664,9 @@ struct ScrHttpRes {
|
||||
bool destroyed; /* res.destroy()/teardown — res.destroyed (true in 'close') */
|
||||
bool unflushed; /* the socket closed before the body went out: no 'finish' */
|
||||
bool socket_detached; /* finish/close removes the response's socket view */
|
||||
bool socket_assigned; /* the parser handed the socket over after the
|
||||
* response.created/request.start publishes, before
|
||||
* the 'request' listeners (Node's assignSocket) */
|
||||
/* cork()/uncork(): corked counts the nesting (res.writableCorked);
|
||||
* writes while corked coalesce in cork_buf and flush as ONE write when
|
||||
* the count reaches zero (or at end()) — Node's coalescing, and the
|
||||
@@ -1803,7 +1806,8 @@ bool scr_http_res_strict_content_length(ScrHttpRes *r) { return r->strict_conten
|
||||
void scr_http_res_set_strict_content_length(ScrHttpRes *r, bool value) { r->strict_content_length = value; }
|
||||
ScrHttpReq *scr_http_res_request(ScrHttpRes *r) { return scr_http_req_retain(r->req_ref); }
|
||||
ScrNetSocket *scr_http_res_socket(ScrHttpRes *r) {
|
||||
return r->sock && !r->socket_detached ? scr_net_sock_retain(r->sock) : NULL;
|
||||
return r->sock && r->socket_assigned && !r->socket_detached ? scr_net_sock_retain(r->sock)
|
||||
: NULL;
|
||||
}
|
||||
/* HTTP/1 writableFinished turns true where 'finish' is emitted, not when
|
||||
* end() returns; the h2 compat response keeps its stream's answer. */
|
||||
@@ -4352,6 +4356,125 @@ static ScrAlsCtx *scr_http_emit_ctx(const ScrHttpEmit *e) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ── the HTTP/1 server's diagnostics channels ────────────────────────────
|
||||
*
|
||||
* Node's _http_server publishes three process-global channels for every
|
||||
* request that reaches parserOnIncoming:
|
||||
*
|
||||
* http.server.response.created { request, response }
|
||||
* http.server.request.start { request, response, socket, server }
|
||||
* http.server.response.finish { request, response, socket, server }
|
||||
*
|
||||
* response.created publishes from the ServerResponse constructor and
|
||||
* request.start just after it, both before the 'request' listeners run (and
|
||||
* before the maxRequestsPerSocket and Expect decisions, so a request the
|
||||
* server drops or answers 417 still publishes them). response.finish
|
||||
* publishes from the server's own 'finish' listener, which Node registers
|
||||
* ahead of any the program adds. CONNECT and Upgrade requests never reach
|
||||
* the response creation — 'connect'/'upgrade' take the socket raw — so they
|
||||
* publish none of these, and the HTTP/2 compatibility layer's responses
|
||||
* are not ServerResponses in Node either, so they are excluded here too.
|
||||
*
|
||||
* Each publish is guarded by hasSubscribers and the message is built only
|
||||
* then. The channels belong to the diagnostics-channel unit, which a
|
||||
* program links only when it imports node:diagnostics_channel:
|
||||
* `scr_optional_dc` is NULL otherwise. Handles resolve lazily and are
|
||||
* cached, the registry interning a name for the process. */
|
||||
|
||||
enum {
|
||||
SCR_HTTP_SRV_DC_RESPONSE_CREATED,
|
||||
SCR_HTTP_SRV_DC_REQUEST_START,
|
||||
SCR_HTTP_SRV_DC_RESPONSE_FINISH,
|
||||
SCR_HTTP_SRV_DC_CHANNELS,
|
||||
};
|
||||
|
||||
static const char *const scr_http_srv_dc_names[SCR_HTTP_SRV_DC_CHANNELS] = {
|
||||
"http.server.response.created",
|
||||
"http.server.request.start",
|
||||
"http.server.response.finish",
|
||||
};
|
||||
|
||||
static SCR_TL double scr_http_srv_dc_handles[SCR_HTTP_SRV_DC_CHANNELS];
|
||||
static SCR_TL bool scr_http_srv_dc_resolved[SCR_HTTP_SRV_DC_CHANNELS];
|
||||
|
||||
/* The channel's handle, or NaN when the unit is not linked. */
|
||||
static double scr_http_srv_dc_handle(int index) {
|
||||
if (!scr_http_srv_dc_resolved[index]) {
|
||||
scr_http_srv_dc_resolved[index] = true;
|
||||
scr_http_srv_dc_handles[index] = NAN;
|
||||
if (scr_optional_dc != NULL) {
|
||||
const char *name = scr_http_srv_dc_names[index];
|
||||
ScrStr *text = scr_str_new(name, strlen(name));
|
||||
ScrDyn *key = scr_dyn_new_str(text);
|
||||
scr_str_release(text);
|
||||
double handle = scr_optional_dc->channel(key);
|
||||
scr_dyn_release(key);
|
||||
if (handle == handle) scr_http_srv_dc_handles[index] = handle;
|
||||
}
|
||||
}
|
||||
return scr_http_srv_dc_handles[index];
|
||||
}
|
||||
|
||||
static bool scr_http_srv_dc_active(int index) {
|
||||
double handle = scr_http_srv_dc_handle(index);
|
||||
return handle == handle && scr_optional_dc != NULL &&
|
||||
scr_optional_dc->chan_has_subscribers(handle);
|
||||
}
|
||||
|
||||
static void scr_http_srv_dc_publish(int index, ScrDyn *message /*+1*/) {
|
||||
double handle = scr_http_srv_dc_handle(index);
|
||||
if (handle == handle && scr_optional_dc != NULL) scr_optional_dc->publish(handle, message);
|
||||
scr_dyn_release(message);
|
||||
}
|
||||
|
||||
/* The message's first two fields, in Node's key order: the request and the
|
||||
* response the program holds (the same handles its listeners receive). */
|
||||
static ScrDyn *scr_http_srv_dc_pair(ScrHttpReq *req, ScrHttpRes *res) {
|
||||
ScrDyn *message = scr_dyn_new_obj();
|
||||
scr_dyn_obj_set(message, "request", 7, scr_dyn_new_handle(req, SCR_DYNH_HTTP_REQ));
|
||||
scr_dyn_obj_set(message, "response", 8, scr_dyn_new_handle(res, SCR_DYNH_HTTP_RES));
|
||||
return message;
|
||||
}
|
||||
|
||||
/* Appends {socket, server}, the parser's connection and its server. */
|
||||
static void scr_http_srv_dc_add_conn(ScrDyn *message, ScrNetSocket *sock) {
|
||||
scr_dyn_obj_set(message, "socket", 6,
|
||||
sock != NULL ? scr_dyn_new_handle(sock, SCR_DYNH_NET_SOCKET)
|
||||
: scr_dyn_retain(scr_dyn_undefined()));
|
||||
ScrNetServer *server = sock != NULL ? scr_net_sock_server(sock) : NULL;
|
||||
scr_dyn_obj_set(message, "server", 6,
|
||||
server != NULL ? scr_dyn_new_handle(server, SCR_DYNH_NET_SERVER)
|
||||
: scr_dyn_retain(scr_dyn_undefined()));
|
||||
}
|
||||
|
||||
/* ServerResponse's constructor: { request, response }, before request.start. */
|
||||
static void scr_http_srv_dc_response_created(ScrHttpReq *req, ScrHttpRes *res) {
|
||||
if (!scr_http_srv_dc_active(SCR_HTTP_SRV_DC_RESPONSE_CREATED)) return;
|
||||
scr_http_srv_dc_publish(SCR_HTTP_SRV_DC_RESPONSE_CREATED, scr_http_srv_dc_pair(req, res));
|
||||
}
|
||||
|
||||
/* parserOnIncoming after the response exists: the 'request' listeners run
|
||||
* next. */
|
||||
static void scr_http_srv_dc_request_start(ScrHttpReq *req, ScrHttpRes *res, ScrNetSocket *sock) {
|
||||
if (!scr_http_srv_dc_active(SCR_HTTP_SRV_DC_REQUEST_START)) return;
|
||||
ScrDyn *message = scr_http_srv_dc_pair(req, res);
|
||||
scr_http_srv_dc_add_conn(message, sock);
|
||||
scr_http_srv_dc_publish(SCR_HTTP_SRV_DC_REQUEST_START, message);
|
||||
}
|
||||
|
||||
/* The response's 'finish' (Node's resOnFinish listener): { request,
|
||||
* response, socket, server }, ahead of the program's finish listeners. Only
|
||||
* an HTTP/1 response has a parsed request behind it; the HTTP/2
|
||||
* compatibility response is not a ServerResponse in Node. */
|
||||
static void scr_http_srv_dc_response_finish(ScrHttpRes *res) {
|
||||
if (!scr_http_srv_dc_active(SCR_HTTP_SRV_DC_RESPONSE_FINISH)) return;
|
||||
ScrHttpReq *req = res->req_ref;
|
||||
if (req == NULL || req->h2_stream != NULL) return;
|
||||
ScrDyn *message = scr_http_srv_dc_pair(req, res);
|
||||
scr_http_srv_dc_add_conn(message, res->sock);
|
||||
scr_http_srv_dc_publish(SCR_HTTP_SRV_DC_RESPONSE_FINISH, message);
|
||||
}
|
||||
|
||||
/* A 'finish' held up by the socket's buffer re-queues when the buffer
|
||||
* empties: Node's 'finish' follows afterWrite, not a timer. */
|
||||
|
||||
@@ -4662,8 +4785,18 @@ static void scr_http_proto_sweep(void) {
|
||||
res->endcb_ls = (ScrNetLs){0};
|
||||
scr_net_fire0_this(&endcbs, res, SCR_DYNH_HTTP_RES);
|
||||
scr_net_ls_drop(&endcbs);
|
||||
if (!scr_exc_pending()) {
|
||||
/* Node's server registers its own 'finish' listener (resOnFinish)
|
||||
* before parserOnIncoming reaches the 'request' event: it publishes
|
||||
* the response channel while the response still holds the socket,
|
||||
* detaches the socket, and only then do the program's listeners
|
||||
* run. */
|
||||
scr_http_srv_dc_response_finish(res);
|
||||
}
|
||||
res->socket_detached = true;
|
||||
if (!scr_exc_pending()) scr_net_fire0_this(&res->finish_ls, res, SCR_DYNH_HTTP_RES);
|
||||
if (!scr_exc_pending()) {
|
||||
scr_net_fire0_this(&res->finish_ls, res, SCR_DYNH_HTTP_RES);
|
||||
}
|
||||
/* a 'close' that arrived while these bytes were still buffered runs
|
||||
* now, after the finish listeners — Node's order */
|
||||
if (res->close_after_finish) {
|
||||
@@ -6155,6 +6288,16 @@ static bool scr_http_conn_parse_head(ScrHttpConn *conn, size_t head_len, bool *o
|
||||
conn->res = res;
|
||||
conn->close_after = !req_keep_alive;
|
||||
|
||||
/* Node's parserOnIncoming: the response's constructor publishes
|
||||
* response.created, then request.start goes out — both before the
|
||||
* 'request' listeners and before the maxRequestsPerSocket and Expect
|
||||
* decisions (a dropped or 417 request still publishes them). */
|
||||
scr_http_srv_dc_response_created(req, res);
|
||||
scr_http_srv_dc_request_start(req, res, conn->sock);
|
||||
/* Node's assignSocket runs after those publishes, so the response they
|
||||
* carry has no socket; the 'request' listeners below see it attached. */
|
||||
res->socket_assigned = true;
|
||||
|
||||
if (chunked) {
|
||||
conn->state = SCR_HTTP_CHUNK_SIZE;
|
||||
} else if (content_length > 0) {
|
||||
@@ -7299,6 +7442,7 @@ ScrHttpRes *scr_http_h2_res_new(ScrNetSocket *sock /*borrowed, nullable*/,
|
||||
res->als = scr_als_capture();
|
||||
res->hwm = scr_stream_get_default_hwm(false);
|
||||
res->sock = sock ? scr_net_sock_retain(sock) : NULL;
|
||||
res->socket_assigned = true; /* the compat response reads the session's socket */
|
||||
res->h2_stream = scr_http_h2_ops->retain(stream);
|
||||
res->keep_alive = true; /* inert on h2 — no Connection header exists */
|
||||
#ifdef SCR_RC_AUDIT
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
// The HTTP/1 server diagnostics channels. Node's _http_server publishes
|
||||
// three process-global channels for every request that reaches
|
||||
// parserOnIncoming:
|
||||
//
|
||||
// http.server.response.created { request, response }
|
||||
// http.server.request.start { request, response, socket, server }
|
||||
// http.server.response.finish { request, response, socket, server }
|
||||
//
|
||||
// response.created comes from the ServerResponse constructor and
|
||||
// request.start just after it, both before the 'request' listeners;
|
||||
// response.finish comes from the server's own 'finish' listener, ahead of any
|
||||
// the program adds. A request the server answers itself (the 417 for an
|
||||
// unrecognised Expect, here) still publishes all three and fires no
|
||||
// 'request'.
|
||||
//
|
||||
// The program runs a keep-alive client against a server in the same process:
|
||||
// a GET, a POST with a body, and a 417. Per URL it reports the channel
|
||||
// sequence and each message's shape — key order, the request and response
|
||||
// the program's own listener holds (compared by identity), the socket and
|
||||
// server, the status, and whether the response had finished. The client's
|
||||
// own result closes each block, so the blocks are comparable whatever order
|
||||
// the two ends' events land in.
|
||||
//
|
||||
// The response's own socket view follows Node's assignSocket: it is null in
|
||||
// the created and start messages (the response exists before the parser
|
||||
// hands it the socket) and the message's socket at finish, since the server
|
||||
// publishes that channel before detaching the socket. The program's own
|
||||
// 'finish' listener, registered after the server's, runs after the detach
|
||||
// and sees null.
|
||||
import * as http from "node:http";
|
||||
import * as dc from "node:diagnostics_channel";
|
||||
import type { AddressInfo } from "node:net";
|
||||
|
||||
interface Seen {
|
||||
name: string;
|
||||
request: any;
|
||||
response: any;
|
||||
socket: any;
|
||||
server: any;
|
||||
keys: string[];
|
||||
status: number;
|
||||
finished: boolean;
|
||||
resSocket: string;
|
||||
}
|
||||
|
||||
const seen: Seen[] = [];
|
||||
const handlerReqs: { url: string; req: any; res: any }[] = [];
|
||||
const handlerSockets: { url: string; socket: string }[] = [];
|
||||
const clientLines: { url: string; text: string }[] = [];
|
||||
|
||||
const names = [
|
||||
"http.server.response.created",
|
||||
"http.server.request.start",
|
||||
"http.server.response.finish",
|
||||
];
|
||||
for (const name of names) {
|
||||
dc.subscribe(name, (msg: any) => {
|
||||
seen.push({
|
||||
name,
|
||||
request: msg.request,
|
||||
response: msg.response,
|
||||
socket: msg.socket,
|
||||
server: msg.server,
|
||||
keys: Object.keys(msg),
|
||||
status: msg.response.statusCode,
|
||||
finished: msg.response.writableFinished,
|
||||
resSocket:
|
||||
msg.response.socket === null
|
||||
? "null"
|
||||
: msg.response.socket === msg.socket
|
||||
? "same"
|
||||
: "other",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let server: http.Server;
|
||||
const serverSockets: any[] = [];
|
||||
server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
handlerReqs.push({ url: req.url ?? "", req, res });
|
||||
res.on("finish", () => {
|
||||
handlerSockets.push({ url: req.url ?? "", socket: res.socket === null ? "null" : "socket" });
|
||||
});
|
||||
if (req.url === "/post") {
|
||||
let body = "";
|
||||
req.setEncoding("utf8");
|
||||
req.on("data", (d: string) => (body += d));
|
||||
req.on("end", () => res.end(`got ${body}`));
|
||||
return;
|
||||
}
|
||||
res.setHeader("x-a", "1");
|
||||
res.end("ok");
|
||||
});
|
||||
server.on("connection", (socket) => serverSockets.push(socket));
|
||||
|
||||
function shortName(name: string): string {
|
||||
return name.slice(name.indexOf(".server.") + ".server.".length);
|
||||
}
|
||||
|
||||
function flush(): void {
|
||||
for (const entry of handlerReqs) {
|
||||
const mine = seen.filter((s) => s.request === entry.req);
|
||||
const label = entry.url;
|
||||
console.log(`${label} sequence=${mine.map((s) => shortName(s.name)).join(",")}`);
|
||||
for (const s of mine) {
|
||||
const parts = [`${label} ${shortName(s.name)} keys=${s.keys.join(",")}`];
|
||||
parts.push(`request=${s.request === entry.req} response=${s.response === entry.res}`);
|
||||
const hasSocket = s.keys.indexOf("socket") >= 0;
|
||||
if (hasSocket) {
|
||||
parts.push(`server=${s.server === server}`);
|
||||
parts.push(`socket=${serverSockets.indexOf(s.socket) >= 0 ? "connection" : "other"}`);
|
||||
}
|
||||
parts.push(`status=${s.status} finished=${s.finished} resSocket=${s.resSocket}`);
|
||||
console.log(parts.join(" "));
|
||||
}
|
||||
const handlerSocket = handlerSockets.find((h) => h.url === label);
|
||||
if (handlerSocket) console.log(`${label} handler-finish socket=${handlerSocket.socket}`);
|
||||
}
|
||||
// the 417 request never reaches the handler: report it from its identifier
|
||||
for (const s of seen) {
|
||||
if (handlerReqs.some((e) => e.req === s.request)) continue;
|
||||
if (s.name !== "http.server.response.created") continue;
|
||||
const mine = seen.filter((m) => m.request === s.request);
|
||||
console.log(`${s.request.url} sequence=${mine.map((m) => shortName(m.name)).join(",")}`);
|
||||
for (const m of mine) {
|
||||
console.log(
|
||||
`${s.request.url} ${shortName(m.name)} keys=${m.keys.join(",")} status=${m.status} finished=${m.finished} resSocket=${m.resSocket}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const c of clientLines) console.log(c.text);
|
||||
seen.length = 0;
|
||||
}
|
||||
|
||||
function get(path: string, options: http.RequestOptions, body?: string): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
const req = http.request(options, (res) => {
|
||||
let text = "";
|
||||
res.setEncoding("utf8");
|
||||
res.on("data", (d: string) => (text += d));
|
||||
res.on("end", () => {
|
||||
clientLines.push({ url: path, text: `client ${path} ${res.statusCode} ${text}` });
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
if (body !== undefined) req.end(body);
|
||||
else req.end();
|
||||
});
|
||||
}
|
||||
|
||||
server.listen(0, "127.0.0.1", () => {
|
||||
const port = (server.address() as AddressInfo).port;
|
||||
const agent = new http.Agent({ keepAlive: true, maxSockets: 1 });
|
||||
const base: http.RequestOptions = { host: "127.0.0.1", port, agent };
|
||||
get("/one", { ...base, path: "/one" })
|
||||
.then(() => get("/post", { ...base, path: "/post", method: "POST" }, "abc"))
|
||||
.then(() => get("/expect", { ...base, path: "/expect", headers: { Expect: "nonsense" } }))
|
||||
.then(() => {
|
||||
agent.destroy();
|
||||
server.close(() => {
|
||||
flush();
|
||||
console.log("done");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
{ "plain": 2300, "san": 5300 }
|
||||
Reference in New Issue
Block a user