Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TLS over TLS HTTP request. Works in node v0.11.9, throws "Error: stream.push() after EOF" on v0.11.10. `git-bisect` says: 1e066e4a4a88f97af865d965f104b5fe8136797f is the first bad commit
HTTP 33749: agent.request { agent:
{ domain: null,
_events: {},
_maxListeners: undefined,
callback: [Function: connect],
secureProxy: true,
secureEndpoint: true,
proxy:
{ protocol: 'https:',
slashes: true,
auth: null,
host: '127.0.0.1',
port: 58001,
hostname: '127.0.0.1',
hash: null,
search: null,
query: null,
href: 'https://127.0.0.1:58001/',
rejectUnauthorized: false,
parse: [Function],
format: [Function],
resolve: [Function],
resolveObject: [Function],
parseHost: [Function] } },
keepAlive: false,
rejectUnauthorized: false,
href: 'https://127.0.0.1:58000/',
path: '/',
pathname: '/',
query: null,
search: null,
hash: null,
hostname: '127.0.0.1',
port: '58000',
host: '127.0.0.1',
auth: null,
slashes: true,
protocol: 'https:' }
NET 33749: pipe false undefined
NET 33749: connect: find host 127.0.0.1
NET 33749: _read
NET 33749: _read wait for connection
HTTP 33749: outgoing message end.
NET 33749: afterConnect
NET 33749: _read
NET 33749: Socket._read readStart
TLS 33749: secure established
NET 33749: afterWrite 0
NET 33749: afterWrite call cb
NET 33749: onread 95
NET 33749: got data
NET 33749: _read
TLS 33749: legacy connect
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 0 bytes
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 320 bytes
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 0 bytes
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write called with 60 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write queued with 60 bytes
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write called with 60 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write queued with 60 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write called with 60 bytes
TLS-LEGACY 33749: cleartext.write queued with 60 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write called with 60 bytes
TLS-LEGACY 33749: cleartext.write queued with 60 bytes
NET 33749: afterWrite 0
NET 33749: afterWrite call cb
NET 33749: onread 839
NET 33749: got data
TLS-LEGACY 33749: encrypted.write called with 839 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write called with 60 bytes
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 191 bytes
TLS-LEGACY 33749: cleartext.write queued with 60 bytes
TLS-LEGACY 33749: encrypted.write succeed with 839 bytes
NET 33749: _read
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write called with 60 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write queued with 60 bytes
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write called with 60 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write queued with 60 bytes
NET 33749: afterWrite 0
NET 33749: afterWrite call cb
NET 33749: onread 258
NET 33749: got data
TLS-LEGACY 33749: encrypted.write called with 258 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: secure established
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: cleartext.write called with 60 bytes
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 89 bytes
TLS-LEGACY 33749: cleartext.write succeed with 60 bytes
TLS-LEGACY 33749: encrypted.write succeed with 258 bytes
NET 33749: _read
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 0 bytes
TLS-LEGACY 33749: encrypted.read called with 16384 bytes
TLS-LEGACY 33749: encrypted.read succeed with 0 bytes
NET 33749: afterWrite 0
NET 33749: afterWrite call cb
NET 33749: onread 250
NET 33749: got data
TLS-LEGACY 33749: encrypted.write called with 250 bytes
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 161 bytes
TLS-LEGACY 33749: encrypted.write succeed with 250 bytes
NET 33749: _read
TLS-LEGACY 33749: cleartext.read called with 16384 bytes
TLS-LEGACY 33749: cleartext.read succeed with 0 bytes
TLS-LEGACY 33749: SecurePair.destroy
TLS-LEGACY 33749: cleartext.destroy
TLS-LEGACY 33749: encrypted.destroy
HTTP 33749: parserOnHeadersComplete { headers:
[ 'Date',
'Thu, 23 Jan 2014 20:01:12 GMT',
'Connection',
'close',
'Transfer-Encoding',
'chunked' ],
statusCode: 200,
statusMessage: 'OK',
versionMajor: 1,
versionMinor: 1,
shouldKeepAlive: false,
upgrade: false }
HTTP 33749: AGENT incoming response!
HTTP 33749: AGENT isHeadResponse false
events.js:82
throw er; // Unhandled 'error' event
^
Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:142:15)
at IncomingMessage.Readable.push (_stream_readable.js:123:10)
at HTTPParser.parserOnBody (_http_common.js:132:22)
at CleartextStream.socketOnData (_http_client.js:277:20)
at CleartextStream.EventEmitter.emit (events.js:101:17)
at CleartextStream.Readable.read (_stream_readable.js:366:10)
at flow (_stream_readable.js:743:26)
at emitReadable_ (_stream_readable.js:419:3)
at _stream_readable.js:409:9
at process._tickCallback (node.js:599:11)
HTTP 45777: agent.request { agent:
{ domain: null,
_events: {},
_maxListeners: undefined,
callback: [Function: connect],
secureProxy: true,
secureEndpoint: true,
proxy:
{ protocol: 'https:',
slashes: true,
auth: null,
host: '127.0.0.1',
port: 58001,
hostname: '127.0.0.1',
hash: null,
search: null,
query: null,
href: 'https://127.0.0.1:58001/',
rejectUnauthorized: false,
parse: [Function],
format: [Function],
resolve: [Function],
resolveObject: [Function],
parseHost: [Function] } },
keepAlive: false,
rejectUnauthorized: false,
href: 'https://127.0.0.1:58000/',
path: '/',
pathname: '/',
query: null,
search: null,
hash: null,
hostname: '127.0.0.1',
port: '58000',
host: '127.0.0.1',
auth: null,
slashes: true,
protocol: 'https:' }
NET 45777: pipe false undefined
NET 45777: connect: find host 127.0.0.1
NET 45777: _read
NET 45777: _read wait for connection
HTTP 45777: outgoing message end.
NET 45777: afterConnect
NET 45777: _read
NET 45777: Socket._read readStart
TLS 45777: secure established
NET 45777: afterWrite 0
NET 45777: afterWrite call cb
NET 45777: onread 95
NET 45777: got data
NET 45777: _read
TLS 45777: legacy connect
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 320 bytes
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write called with 60 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write queued with 60 bytes
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write called with 60 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write queued with 60 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write called with 60 bytes
TLS-LEGACY 45777: cleartext.write queued with 60 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write called with 60 bytes
TLS-LEGACY 45777: cleartext.write queued with 60 bytes
NET 45777: afterWrite 0
NET 45777: afterWrite call cb
NET 45777: onread 839
NET 45777: got data
TLS-LEGACY 45777: encrypted.write called with 839 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write called with 60 bytes
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 191 bytes
TLS-LEGACY 45777: cleartext.write queued with 60 bytes
TLS-LEGACY 45777: encrypted.write succeed with 839 bytes
NET 45777: _read
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write called with 60 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write queued with 60 bytes
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write called with 60 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write queued with 60 bytes
NET 45777: afterWrite 0
NET 45777: afterWrite call cb
NET 45777: onread 258
NET 45777: got data
TLS-LEGACY 45777: encrypted.write called with 258 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: secure established
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
TLS-LEGACY 45777: cleartext.write called with 60 bytes
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 89 bytes
TLS-LEGACY 45777: cleartext.write succeed with 60 bytes
TLS-LEGACY 45777: encrypted.write succeed with 258 bytes
NET 45777: _read
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
NET 45777: afterWrite 0
NET 45777: afterWrite call cb
NET 45777: onread 250
NET 45777: got data
TLS-LEGACY 45777: encrypted.write called with 250 bytes
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 161 bytes
TLS-LEGACY 45777: encrypted.write succeed with 250 bytes
NET 45777: _read
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
HTTP 45777: parserOnHeadersComplete { headers:
[ 'Date',
'Thu, 23 Jan 2014 18:49:35 GMT',
'Connection',
'close',
'Transfer-Encoding',
'chunked' ],
statusCode: 200,
versionMajor: 1,
versionMinor: 1,
shouldKeepAlive: false,
upgrade: false }
HTTP 45777: AGENT incoming response!
HTTP 45777: AGENT isHeadResponse false
TLS-LEGACY 45777: cleartext.read called with 16384 bytes
TLS-LEGACY 45777: cleartext.read succeed with 0 bytes
HTTP 45777: AGENT socket.destroySoon()
TLS-LEGACY 45777: cleartext.destroySoon
TLS-LEGACY 45777: cleartext.end
TLS-LEGACY 45777: cleartext.onfinish
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 31 bytes
Success!!!
TLS-LEGACY 45777: encrypted.read called with 16384 bytes
TLS-LEGACY 45777: encrypted.read succeed with 0 bytes
TLS-LEGACY 45777: encrypted.onend
TLS-LEGACY 45777: cleartext.destroy
TLS-LEGACY 45777: encrypted.destroy
HTTP 45777: HTTP socket close
TLS-LEGACY 45777: cleartext.onend
NET 45777: afterWrite 0
NET 45777: afterWrite call cb
NET 45777: onSocketFinish
NET 45777: oSF: not ended, call shutdown()
NET 45777: destroy undefined
NET 45777: destroy
NET 45777: close
NET 45777: close handle
NET 45777: afterShutdown destroyed=true { highWaterMark: 16384,
buffer: [],
length: 0,
pipes: null,
pipesCount: 0,
flowing: false,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
objectMode: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null,
resumeScheduled: false }
NET 45777: emit close
var fs = require('fs');
var https = require('https');
var Proxy = require('proxy');
var sslServer;
var sslServerPort;
var sslProxy;
var sslProxyPort;
// setup target HTTPS server
var options = {
key: fs.readFileSync(__dirname + '/test/server.key'),
cert: fs.readFileSync(__dirname + '/test/server.crt')
};
sslServer = https.createServer(options, function (req, res) {
res.end(JSON.stringify(req.headers));
});
sslServer.listen(function () {
sslServerPort = sslServer.address().port;
console.log('ssl server port: %d', sslServerPort);
// setup SSL HTTP proxy server
var options = {
key: fs.readFileSync(__dirname + '/test/server.key'),
cert: fs.readFileSync(__dirname + '/test/server.crt')
};
sslProxy = Proxy(https.createServer(options));
sslProxy.listen(function () {
sslProxyPort = sslProxy.address().port;
console.log('ssl proxy port: %d', sslProxyPort);
});
});
var url = require('url');
var https = require('https');
var assert = require('assert');
var HttpsProxyAgent = require('https-proxy-agent');
var sslServerPort = +process.argv[2];
var sslProxyPort = +process.argv[3];
var proxy = 'https://127.0.0.1:' + sslProxyPort;
proxy = url.parse(proxy);
// `rejectUnauthorized` is actually necessary this time since the HTTPS
// proxy server itself is using a self-signed SSL certificate…
proxy.rejectUnauthorized = false;
var agent = new HttpsProxyAgent(proxy);
var opts = url.parse('https://127.0.0.1:' + sslServerPort);
opts.agent = agent;
opts.rejectUnauthorized = false;
https.get(opts, function (res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function (b) {
data += b;
});
res.on('end', function () {
data = JSON.parse(data);
assert.equal('127.0.0.1:' + sslServerPort, data.host);
done();
});
});
function done (err) {
if (err) throw err;
console.log('Success!!!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.