(req, res)
| 53 | } |
| 54 | |
| 55 | const 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 | |
| 89 | const httpServer = http.createServer(handleRequest); |
| 90 |
nothing calls this directly
no test coverage detected