revise installing a license file
[platform/upstream/nodejs.git] / test / parallel / test-http-localaddress.js
1 'use strict';
2 const common = require('../common');
3 const http = require('http');
4 const assert = require('assert');
5
6 if (!common.hasMultiLocalhost()) {
7   console.log('1..0 # Skipped: platform-specific test.');
8   return;
9 }
10
11 var server = http.createServer(function(req, res) {
12   console.log('Connect from: ' + req.connection.remoteAddress);
13   assert.equal('127.0.0.2', req.connection.remoteAddress);
14
15   req.on('end', function() {
16     res.writeHead(200, { 'Content-Type': 'text/plain' });
17     res.end('You are from: ' + req.connection.remoteAddress);
18   });
19   req.resume();
20 });
21
22 server.listen(common.PORT, '127.0.0.1', function() {
23   var options = { host: 'localhost',
24     port: common.PORT,
25     path: '/',
26     method: 'GET',
27     localAddress: '127.0.0.2' };
28
29   var req = http.request(options, function(res) {
30     res.on('end', function() {
31       server.close();
32       process.exit();
33     });
34     res.resume();
35   });
36   req.end();
37 });