-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
docIssues and PRs related to the documentations.Issues and PRs related to the documentations.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.questionIssues that look for answers.Issues that look for answers.
Description
- Version: v6.10.0
- Platform: 3.10.0-514.2.2.el7.x86_64 deps: update openssl to 1.0.1j #1 SMP Tue Dec 6 23:06:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux AND Windows 8.1 64
The get method of http and https modules does not check the prototype of the given object. I guess this replicates to all other request/response methods.
The following code is ran on a machine that does not have anything running on port 8989:
'use strict';
const http = require("http");
let options = {
port: 8989
};
let optionsChild = Object.create(options);
http.get(options, function () {
console.log("Success options");
}).on('error', console.error);
http.get(optionsChild, function () {
console.log("Success optionsChild");
}).on('error', console.error);
And we receive the following output:
{ Error: connect ECONNREFUSED 127.0.0.1:8989
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8989 }
Success optionsChild
This means the port takes the default value and successfully connects instead of taking the 8989 port from the prototype.
- Is this intended?
The need for this code arose from the necessity to reuse some default options in multiple requests. So I would like to ask a followup question:
- Can reusing(altering) the options Object passed to a http/https request cause unexpected behavior(requests being made to the last value of the object instead of the value at the moment of the function call or performance losses)?
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to the documentations.Issues and PRs related to the documentations.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.questionIssues that look for answers.Issues that look for answers.