MCPcopy
hub / github.com/socketio/socket.io / onPollRequest

Method onPollRequest

packages/engine.io/lib/transports/polling.ts:71–106  ·  view source on GitHub ↗

* The client sends a request awaiting for us to send data. * * @private

(req: EngineRequest, res: ServerResponse)

Source from the content-addressed store, hash-verified

69 * @private
70 */
71 private onPollRequest(req: EngineRequest, res: ServerResponse) {
72 if (this.req) {
73 debug("request overlap");
74 // assert: this.res, '.req and .res should be (un)set together'
75 this.onError("overlap from client");
76 res.writeHead(400);
77 res.end();
78 return;
79 }
80
81 debug("setting request");
82
83 this.req = req;
84 this.res = res;
85
86 const onClose = () => {
87 this.onError("poll connection closed prematurely");
88 };
89
90 const cleanup = () => {
91 req.removeListener("close", onClose);
92 this.req = this.res = null;
93 };
94
95 req.cleanup = cleanup;
96 req.on("close", onClose);
97
98 this.writable = true;
99 this.emit("ready");
100
101 // if we're still writable but had a pending close, trigger an empty send
102 if (this.writable && this.shouldClose) {
103 debug("triggering empty send to append close packet");
104 this.send([{ type: "noop" }]);
105 }
106 }
107
108 /**
109 * The client sends a request with data.

Callers 1

onRequestMethod · 0.95

Calls 7

sendMethod · 0.95
debugFunction · 0.85
emitMethod · 0.65
onErrorMethod · 0.45
writeHeadMethod · 0.45
endMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected