MCPcopy Create free account
hub / github.com/nodejs/node / handleRequest

Function handleRequest

test/parallel/test-inspector-network-http.js:55–87  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

53}
54
55const handleRequest = (req, res) => {
56 const path = getPathName(req);
57 switch (path) {
58 case '/hello-world':
59 setResponseHeaders(res);
60 res.writeHead(200);
61 // Ensure the header is sent.
62 res.write('\n');
63
64 setTimeout(() => {
65 res.end('hello world\n');
66 }, kTimeout);
67 break;
68 case '/echo-post': {
69 const chunks = [];
70 req.on('data', (chunk) => {
71 chunks.push(chunk);
72 });
73 req.on('end', () => {
74 const body = Buffer.concat(chunks).toString();
75 res.setHeader('Content-Type', 'application/json; charset=utf-8');
76 res.writeHead(200);
77 res.end(JSON.stringify({
78 method: req.method,
79 body,
80 }));
81 });
82 break;
83 }
84 default:
85 assert.fail(`Unexpected path: ${path}`);
86 }
87};
88
89const httpServer = http.createServer(handleRequest);
90

Callers

nothing calls this directly

Calls 12

getPathNameFunction · 0.85
writeHeadMethod · 0.80
concatMethod · 0.80
setHeaderMethod · 0.80
setResponseHeadersFunction · 0.70
setTimeoutFunction · 0.50
writeMethod · 0.45
endMethod · 0.45
onMethod · 0.45
pushMethod · 0.45
toStringMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected