mirror of https://github.com/nodejs/node.git
Add bytesWritten to tls.CryptoStream
This adds a proxy for bytesWritten to the tls.CryptoStream. This change makes the connection object more similar between HTTP and HTTPS requests in an effort to avoid confusion. See issue #4650 for more background information.pull/24504/head
parent
f64742ea07
commit
595b5974d7
|
@ -449,6 +449,15 @@ gets high.
|
|||
The number of concurrent connections on the server.
|
||||
|
||||
|
||||
## Class: CryptoStream
|
||||
|
||||
This is an encrypted stream.
|
||||
|
||||
### cryptoStream.bytesWritten
|
||||
|
||||
A proxy to the underlying socket's bytesWritten accessor, this will return
|
||||
the total bytes written to the socket, *including the TLS overhead*.
|
||||
|
||||
## Class: tls.CleartextStream
|
||||
|
||||
This is a stream on top of the *Encrypted* stream that makes it possible to
|
||||
|
|
|
@ -336,6 +336,9 @@ CryptoStream.prototype.setKeepAlive = function(enable, initialDelay) {
|
|||
if (this.socket) this.socket.setKeepAlive(enable, initialDelay);
|
||||
};
|
||||
|
||||
CryptoStream.prototype.__defineGetter__('bytesWritten', function() {
|
||||
return this.socket ? this.socket.bytesWritten : 0;
|
||||
});
|
||||
|
||||
CryptoStream.prototype.setEncoding = function(encoding) {
|
||||
var StringDecoder = require('string_decoder').StringDecoder; // lazy load
|
||||
|
@ -689,7 +692,6 @@ CleartextStream.prototype.__defineGetter__('remotePort', function() {
|
|||
return this.socket && this.socket.remotePort;
|
||||
});
|
||||
|
||||
|
||||
function EncryptedStream(pair) {
|
||||
CryptoStream.call(this, pair);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
// 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.
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var http = require('http');
|
||||
|
||||
var body = 'hello world\n';
|
||||
|
||||
var httpServer = http.createServer(function(req, res) {
|
||||
res.on('finish', function() {
|
||||
assert(typeof(req.connection.bytesWritten) === 'number');
|
||||
assert(req.connection.bytesWritten > 0);
|
||||
httpServer.close();
|
||||
console.log('ok');
|
||||
});
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
res.end(body);
|
||||
});
|
||||
|
||||
httpServer.listen(common.PORT, function() {
|
||||
http.get({ port: common.PORT });
|
||||
});
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
// 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.
|
||||
|
||||
if (!process.versions.openssl) {
|
||||
console.error('Skipping because node compiled without OpenSSL.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
|
||||
var options = {
|
||||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
||||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
||||
};
|
||||
|
||||
var body = 'hello world\n';
|
||||
|
||||
var httpsServer = https.createServer(options, function(req, res) {
|
||||
res.on('finish', function() {
|
||||
assert(typeof(req.connection.bytesWritten) === 'number');
|
||||
assert(req.connection.bytesWritten > 0);
|
||||
httpsServer.close();
|
||||
console.log('ok');
|
||||
});
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
res.end(body);
|
||||
});
|
||||
|
||||
httpsServer.listen(common.PORT, function() {
|
||||
https.get({
|
||||
port: common.PORT,
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue