File
Blob: src/workerd/api/node/tests/http-outgoing-nodejs-server.js
| 1 | // Copyright (c) 2017-2022 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | // This is a sidecar that runs alongside the http-client-nodejs-test.* tests. |
| 6 | // It is executed using the appropriate Node.js version defined in build/deps/nodejs.MODULE.bazel. |
| 7 | const http = require('node:http'); |
| 8 | const assert = require('node:assert/strict'); |
| 9 | |
| 10 | function reportPort(server) { |
| 11 | const address = server.address(); |
| 12 | console.info(`Listening on ${address.address}:${address.port}`); |
| 13 | } |
| 14 | |
| 15 | const finishWritableServer = http.createServer((req, res) => { |
| 16 | assert.strictEqual(res.writable, true); |
| 17 | assert.strictEqual(res.finished, false); |
| 18 | assert.strictEqual(res.writableEnded, false); |
| 19 | res.end(); |
| 20 | |
| 21 | // res.writable is set to false after it has finished sending |
| 22 | // Ref: https://github.com/nodejs/node/issues/15029 |
| 23 | assert.strictEqual(res.writable, true); |
| 24 | assert.strictEqual(res.finished, true); |
| 25 | assert.strictEqual(res.writableEnded, true); |
| 26 | }); |
| 27 | finishWritableServer.listen( |
| 28 | process.env.FINISH_WRITABLE_PORT, |
| 29 | process.env.SIDECAR_HOSTNAME, |
| 30 | () => reportPort(finishWritableServer) |
| 31 | ); |
| 32 | |
| 33 | const writableFinishedServer = http.createServer((req, res) => { |
| 34 | assert.strictEqual(res.writableFinished, false); |
| 35 | res.on('finish', () => { |
| 36 | assert.strictEqual(res.writableFinished, true); |
| 37 | }); |
| 38 | res.end(); |
| 39 | }); |
| 40 | writableFinishedServer.listen( |
| 41 | process.env.WRITABLE_FINISHED_PORT, |
| 42 | process.env.SIDECAR_HOSTNAME, |
| 43 | () => reportPort(writableFinishedServer) |
| 44 | ); |
| 45 | |
| 46 | const propertiesServer = http.createServer((req, res) => { |
| 47 | res.end(); |
| 48 | }); |
| 49 | propertiesServer.listen( |
| 50 | process.env.PROPERTIES_PORT, |
| 51 | process.env.SIDECAR_HOSTNAME, |
| 52 | () => reportPort(propertiesServer) |
| 53 | ); |