'Response from JS request library changes behavior when used with "response.on"
I am new to nodeJS and wanted help to understand the behavior. I am making a simple request to get zip/json/yaml files using
- Method 1:
return http.request(options).on('response', (response, body) => {
var body = [];
//console.log(response)
resolve(response)
});
- Method 2
const req = http.request(options, (res) => {
if (res.statusCode < 200 || res.statusCode >= 300) {
return reject(new Error('statusCode=' + res.statusCode));
}
var body = [];
const response = lodash.cloneDeep(res);
//console.log(res)
res.on('data', function(chunk) {
body.push(chunk);
});
res.on('end', function() {
try {
body = JSON.parse(Buffer.concat(body).toString());
} catch(e) {
reject(e);
}
resolve({body, header: res.headers, response});
});
});
req.on('error', (e) => {
reject(e.message);
});
// send the request
req.end();
And then using response again to send binary zip data. I need both data and response for two different operations. Issue is, when using response.on(, my response object changes is no longer same. Cloning the object has also not solved.
Here are two different responses from above two codes:
- Method 1 o/p:
<ref *2> IncomingMessage {
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: [Object], tail: [Object], length: 1 },
length: 294,
pipes: [],
flowing: null,
ended: false,
endEmitted: false,
reading: false,
constructed: true,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
destroyed: false,
errored: null,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: true,
dataEmitted: false,
decoder: null,
encoding: null,
[Symbol(kPaused)]: null
},
_events: [Object: null prototype] { end: [Function: responseOnEnd] },
_eventsCount: 1,
_maxListeners: undefined,
socket: <ref *1> TLSSocket {
_tlsOptions: {
allowHalfOpen: undefined,
pipe: false,
secureContext: [SecureContext],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined,
enableTrace: undefined,
pskCallback: undefined,
highWaterMark: undefined,
onread: undefined,
signal: undefined
},
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'jsonplaceholder.typicode.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype] {
close: [Array],
end: [Array],
newListener: [Function: keylogNewListener],
secure: [Function: onConnectSecure],
session: [Function (anonymous)],
free: [Function: onFree],
timeout: [Array],
agentRemove: [Function: onRemove],
error: [Function: socketErrorListener],
data: [Function: socketOnData],
drain: [Function: ondrain]
},
_eventsCount: 11,
connecting: false,
_hadError: false,
_parent: null,
_host: 'jsonplaceholder.typicode.com',
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: true,
ended: false,
endEmitted: false,
reading: true,
constructed: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: false,
autoDestroy: true,
destroyed: false,
errored: null,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
dataEmitted: true,
decoder: null,
encoding: null,
[Symbol(kPaused)]: false
},
_maxListeners: undefined,
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: false,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: TLSWrap {
_parent: [TCP],
_parentWrap: undefined,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *1]
},
_requestCert: true,
_rejectUnauthorized: true,
parser: HTTPParser {
'0': null,
'1': [Function: parserOnHeaders],
'2': [Function: parserOnHeadersComplete],
'3': [Function: parserOnBody],
'4': [Function: parserOnMessageComplete],
'5': null,
'6': null,
_headers: [],
_url: '',
socket: [Circular *1],
incoming: [Circular *2],
outgoing: [ClientRequest],
maxHeaderPairs: 2000,
_consumed: false,
onIncoming: [Function: parserOnIncomingClient],
[Symbol(owner_symbol)]: [HTTPClientAsyncResource]
},
_httpMessage: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 1,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [Circular *1],
_header: 'GET /todos HTTP/1.1\r\n' +
'Host: jsonplaceholder.typicode.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/todos',
_ended: false,
res: [Circular *2],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: [HTTPParser],
maxHeadersCount: null,
reusedSocket: false,
host: 'jsonplaceholder.typicode.com',
protocol: 'https:',
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
[Symbol(res)]: TLSWrap {
_parent: [TCP],
_parentWrap: undefined,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *1]
},
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 4,
[Symbol(kHandle)]: TLSWrap {
_parent: [TCP],
_parentWrap: undefined,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *1]
},
[Symbol(kSetNoDelay)]: false,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: {
rejectUnauthorized: true,
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA',
checkServerIdentity: [Function: checkServerIdentity],
minDHSize: 1024,
host: 'jsonplaceholder.typicode.com',
path: null,
port: 443,
method: 'GET',
_defaultAgent: [Agent],
servername: 'jsonplaceholder.typicode.com',
_agentKey: 'jsonplaceholder.typicode.com:443:::::::::::::::::::::',
encoding: null,
singleUse: true
},
[Symbol(RequestTimeout)]: undefined
},
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: false,
rawHeaders: [
'Date',
'Mon, 18 Apr 2022 16:11:29 GMT',
'Content-Type',
'application/json; charset=utf-8',
'Transfer-Encoding',
'chunked',
'Connection',
'close',
'X-Powered-By',
'Express',
'X-Ratelimit-Limit',
'1000',
'X-Ratelimit-Remaining',
'995',
'X-Ratelimit-Reset',
'1648223368',
'Vary',
'Origin, Accept-Encoding',
'Access-Control-Allow-Credentials',
'true',
'Cache-Control',
'max-age=43200',
'Pragma',
'no-cache',
'Expires',
'-1',
'X-Content-Type-Options',
'nosniff',
'Etag',
'W/"5ef7-4Ad6/n39KWY9q6Ykm/ULNQ2F5IM"',
'Via',
'1.1 vegur',
'CF-Cache-Status',
'HIT',
'Age',
'21762',
'Expect-CT',
'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
'Report-To',
'{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=WcXWuUtaP%2FoGSUN2bhgMIzKDY0jJ52%2Bo%2F8AvwyEyoXX8LBs8lOoj9y1S5VwJta%2Fa0ThoSoR37%2BJBN4FgVoBAi50b0DiNUHsYmwwjalURyuYQFT0bPfzjE6VSrrW8k%2Fxt%2FHELjHfT%2Fzqtu0sXjx5a"}],"group":"cf-nel","max_age":604800}',
'NEL',
'{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
'Server',
'cloudflare',
'CF-RAY',
'6fdead362a346840-SEA',
'alt-svc',
'h3=":443"; ma=86400, h3-29=":443"; ma=86400'
],
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 200,
statusMessage: 'OK',
client: <ref *1> TLSSocket {
_tlsOptions: {
allowHalfOpen: undefined,
pipe: false,
secureContext: [SecureContext],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined,
enableTrace: undefined,
pskCallback: undefined,
highWaterMark: undefined,
onread: undefined,
signal: undefined
...
}
- Method 2 o/p:
<ref *2> IncomingMessage {
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: null,
ended: false,
endEmitted: false,
reading: false,
constructed: true,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
destroyed: false,
errored: null,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: true,
dataEmitted: false,
decoder: null,
encoding: null,
[Symbol(kPaused)]: null
},
_events: { end: [Function: responseOnEnd] },
_eventsCount: 1,
_maxListeners: undefined,
socket: <ref *1> TLSSocket {
_tlsOptions: {
allowHalfOpen: undefined,
pipe: false,
secureContext: [SecureContext],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined,
enableTrace: undefined,
pskCallback: undefined,
highWaterMark: undefined,
onread: undefined,
signal: undefined
},
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'jsonplaceholder.typicode.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: {
close: [Array],
end: [Array],
newListener: [Function: keylogNewListener],
secure: [Function: onConnectSecure],
session: [Function (anonymous)],
free: [Function: onFree],
timeout: [Array],
agentRemove: [Function: onRemove],
error: [Function: socketErrorListener],
data: [Function: socketOnData],
drain: [Function: ondrain]
},
_eventsCount: 11,
connecting: false,
_hadError: false,
_parent: null,
_host: 'jsonplaceholder.typicode.com',
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: true,
ended: false,
endEmitted: false,
reading: false,
constructed: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: false,
autoDestroy: true,
destroyed: false,
errored: null,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
dataEmitted: true,
decoder: null,
encoding: null,
[Symbol(kPaused)]: false
},
_maxListeners: undefined,
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: false,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: TLSWrap {
_parent: [TCP],
_parentWrap: undefined,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *1]
},
_requestCert: true,
_rejectUnauthorized: true,
parser: HTTPParser {
'0': null,
'1': [Function: parserOnHeaders],
'2': [Function: parserOnHeadersComplete],
'3': [Function: parserOnBody],
'4': [Function: parserOnMessageComplete],
'5': null,
'6': null,
_headers: [],
_url: '',
socket: [Circular *1],
incoming: [Circular *2],
outgoing: [ClientRequest],
maxHeaderPairs: 2000,
_consumed: false,
onIncoming: [Function: parserOnIncomingClient],
[Symbol(owner_symbol)]: [HTTPClientAsyncResource]
},
_httpMessage: ClientRequest {
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [Circular *1],
_header: 'GET /todos HTTP/1.1\r\n' +
'Host: jsonplaceholder.typicode.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/todos',
_ended: false,
res: [Circular *2],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: [HTTPParser],
maxHeadersCount: null,
reusedSocket: false,
host: 'jsonplaceholder.typicode.com',
protocol: 'https:',
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object]
},
[Symbol(res)]: TLSWrap {
_parent: [TCP],
_parentWrap: undefined,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *1]
},
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 4,
[Symbol(kHandle)]: TLSWrap {
_parent: [TCP],
_parentWrap: undefined,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *1]
},
[Symbol(kSetNoDelay)]: false,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: {
rejectUnauthorized: true,
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA',
checkServerIdentity: [Function: checkServerIdentity],
minDHSize: 1024,
host: 'jsonplaceholder.typicode.com',
path: null,
port: 443,
method: 'GET',
encoing: null,
_defaultAgent: [Agent],
servername: 'jsonplaceholder.typicode.com',
_agentKey: 'jsonplaceholder.typicode.com:443:::::::::::::::::::::',
encoding: null,
singleUse: true
},
[Symbol(RequestTimeout)]: undefined
},
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: false,
rawHeaders: [
'Date',
'Mon, 18 Apr 2022 16:16:15 GMT',
'Content-Type',
'application/json; charset=utf-8',
'Transfer-Encoding',
'chunked',
'Connection',
'close',
'X-Powered-By',
'Express',
'X-Ratelimit-Limit',
'1000',
'X-Ratelimit-Remaining',
'999',
'X-Ratelimit-Reset',
'1649790178',
'Vary',
'Origin, Accept-Encoding',
'Access-Control-Allow-Credentials',
'true',
'Cache-Control',
'max-age=43200',
'Pragma',
'no-cache',
'Expires',
'-1',
'X-Content-Type-Options',
'nosniff',
'Etag',
'W/"5ef7-4Ad6/n39KWY9q6Ykm/ULNQ2F5IM"',
'Via',
'1.1 vegur',
'CF-Cache-Status',
'HIT',
'Age',
'19908',
'Expect-CT',
'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
'Report-To',
'{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=pvOM6nEa3WP4jYtxuba%2F%2Bs8hPt0j%2BFRdr0PHJKM%2F3sFTLscxtuDVpf0zHfMZZbzlQtmGsPPw3N2LNRAf5VwGo1jrbWUTtRVhxIvUcgAYjeREES%2Bnmwxuth0P4Murf6sZ9Z7%2BqqF8aFnum4vUU8cB"}],"group":"cf-nel","max_age":604800}',
'NEL',
'{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
'Server',
'cloudflare',
'CF-RAY',
'6fdeb431dbba2934-ORD',
'alt-svc',
'h3=":443"; ma=86400, h3-29=":443"; ma=86400'
],
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 200,
statusMessage: 'OK',
client: <ref *1> TLSSocket {
_tlsOptions: {
allowHalfOpen: undefined,
pipe: false,
secureContext: [SecureContext],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined,
enableTrace: undefined,
pskCallback: undefined,
highWaterMark: undefined,
onread: undefined,
signal: undefined
},
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'jsonplaceholder.typicode.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: {
close: [Array],
end: [Array],
newListener: [Function: keylogNewListener],
secure: [Function: onConnectSecure],
session: [Function (anonymous)],
free: [Function: onFree],
timeout: [Array],
agentRemove: [Function: onRemove],
error: [Function: socketErrorListener],
data: [Function: socketOnData],
drain: [Function: ondrain]
},
_eventsCount: 11,
connecting: false,
_hadError: false,
_parent: null,
_host: 'jsonplaceholder.typicode.com',
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: true,
ended: false,
endEmitted: false,
reading: false,
constructed: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: false,
autoDestroy: true,
destroyed: false,
errored: null,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
dataEmitted: true,
decoder: null,
encoding: null,
[Symbol(kPaused)]: false
},
_maxListeners: undefined,
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: false,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: TLSWrap {
_parent: [TCP],
_parentWrap: undefined,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *1]
},
_requestCert: true,
_rejectUnauthorized: true,
parser: HTTPParser {
'0': null,
'1': [Function: parserOnHeaders],
'2': [Function: parserOnHeadersComplete],
'3': [Function: parserOnBody],
'4': [Function: parserOnMessageComplete],
'5': null,
'6': null,
_headers: [],
_url: '',
socket: [Circular *1],
incoming: [Circular *2],
outgoing: [ClientRequest],
maxHeaderPairs: 2000,
_consumed: false,
onIncoming: [Function: parserOnIncomingClient],
[Symbol(owner_symbol)]: [HTTPClientAsyncResource]
},
_httpMessage: ClientRequest {
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [Circular *1],
_header: 'GET /todos HTTP/1.1\r\n' +
'Host: jsonplaceholder.typicode.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/todos',
_ended: false,
res: [Circular *2],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: [HTTPParser],
maxHeadersCount: null,
reusedSocket: false,
host: 'jsonplaceholder.typicode.com',
protocol: 'https:',
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object]
},
[Symbol(res)]: TLSWrap {
_parent: [TCP],
_parentWrap: undefined,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *1]
},
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 4,
...
}
Any help really appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
