diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/node_compat/config.json | 1 | ||||
-rw-r--r-- | cli/tests/node_compat/test/common/index.js | 3 | ||||
-rw-r--r-- | cli/tests/node_compat/test/parallel/test-http-localaddress.js | 64 |
3 files changed, 68 insertions, 0 deletions
diff --git a/cli/tests/node_compat/config.json b/cli/tests/node_compat/config.json index 60d5beb34..e77f00876 100644 --- a/cli/tests/node_compat/config.json +++ b/cli/tests/node_compat/config.json @@ -346,6 +346,7 @@ "test-http-agent-getname.js", "test-http-client-get-url.js", "test-http-client-read-in-error.js", + "test-http-localaddress.js", "test-http-outgoing-buffer.js", "test-http-outgoing-internal-headernames-getter.js", "test-http-outgoing-internal-headernames-setter.js", diff --git a/cli/tests/node_compat/test/common/index.js b/cli/tests/node_compat/test/common/index.js index f93f7b7a6..491dabd2f 100644 --- a/cli/tests/node_compat/test/common/index.js +++ b/cli/tests/node_compat/test/common/index.js @@ -446,6 +446,9 @@ module.exports = { getArrayBufferViews, getBufferSources, hasCrypto: true, + hasMultiLocalhost() { + return false; + }, invalidArgTypeHelper, mustCall, mustCallAtLeast, diff --git a/cli/tests/node_compat/test/parallel/test-http-localaddress.js b/cli/tests/node_compat/test/parallel/test-http-localaddress.js new file mode 100644 index 000000000..4d2f6fd9b --- /dev/null +++ b/cli/tests/node_compat/test/parallel/test-http-localaddress.js @@ -0,0 +1,64 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually + +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// Flags: --expose-internals +'use strict'; +const common = require('../common'); +if (!common.hasMultiLocalhost()) + common.skip('platform-specific test.'); + +const http = require('http'); +const assert = require('assert'); + +const server = http.createServer((req, res) => { + console.log(`Connect from: ${req.connection.remoteAddress}`); + assert.strictEqual(req.connection.remoteAddress, '127.0.0.2'); + + req.on('end', () => { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end(`You are from: ${req.connection.remoteAddress}`); + }); + req.resume(); +}); + +server.listen(0, '127.0.0.1', () => { + const options = { host: 'localhost', + port: server.address().port, + family: 4, + path: '/', + method: 'GET', + localAddress: '127.0.0.2' }; + + const req = http.request(options, function(res) { + res.on('end', () => { + server.close(); + }); + res.resume(); + }); + req.end(); +}); |