Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

Commit a27fbc6

Browse files
committed
more perf updates
1 parent 3cdd529 commit a27fbc6

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

lib/internal/http2.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,17 +1307,19 @@ function initializeTLSOptions(options) {
13071307
return options;
13081308
}
13091309

1310+
function onErrorSecureServerSession(err, conn) {
1311+
if (!this.emit('clientError', err, conn))
1312+
conn.destroy(err);
1313+
}
1314+
13101315
class Http2SecureServerSession extends TLSServer {
13111316
constructor(options, requestListener) {
13121317
super(initializeTLSOptions(options), connectionListener);
13131318
this[kOptions] = options;
13141319
this.timeout = kDefaultSocketTimeout;
13151320
if (typeof requestListener === 'function')
13161321
this.on('request', requestListener);
1317-
this.on('tlsClientError', (err, conn) => {
1318-
if (!this.emit('clientError', err, conn))
1319-
conn.destroy(err);
1320-
});
1322+
this.on('tlsClientError', onErrorSecureServerSession);
13211323
}
13221324

13231325
setTimeout(msecs, callback) {
@@ -1475,9 +1477,8 @@ class Http2ClientSession extends EventEmitter {
14751477
this[kSocket] = socket;
14761478

14771479
const session = this[kSession] = createClientSession(options, socket);
1478-
socket.once('error', (error) => {
1479-
console.log(error);
1480-
});
1480+
// TODO remove this
1481+
socket.once('error', console.log);
14811482
socket.on('resume', socketOnResume);
14821483
socket.on('pause', socketOnPause);
14831484
socket.on('drain', socketOnDrain);
@@ -1605,20 +1606,7 @@ class Http2ClientRequest extends Http2Outgoing {
16051606
const _handle = this.stream.session.request(mapToHeaders(this[kHeaders]), true);
16061607
if (_handle instanceof http2.Http2Stream) {
16071608
this[kId] = _handle.getId();
1608-
this.stream.once('handle', () => {
1609-
if (this[kTrailers] instanceof Map) {
1610-
for (const v of this[kTrailers]) {
1611-
const key = String(v[0]);
1612-
const value = v[1];
1613-
if (Array.isArray(value) && value.length > 0) {
1614-
for (const item of value)
1615-
this.stream.addTrailer(key, String(item));
1616-
} else {
1617-
this.stream.addTrailer(key, String(value));
1618-
}
1619-
}
1620-
}
1621-
});
1609+
this.stream.once('handle', kBeginSendHandle(this))
16221610
this.stream._handle = _handle;
16231611
}
16241612
}
@@ -1629,6 +1617,23 @@ class Http2ClientRequest extends Http2Outgoing {
16291617
}
16301618
}
16311619

1620+
function kBeginSendHandle(that) {
1621+
return function() {
1622+
if (that[kTrailers] instanceof Map) {
1623+
for (const v of that[kTrailers]) {
1624+
const key = String(v[0]);
1625+
const value = v[1];
1626+
if (Array.isArray(value) && value.length > 0) {
1627+
for (const item of value)
1628+
that.stream.addTrailer(key, String(item));
1629+
} else {
1630+
that.stream.addTrailer(key, String(value));
1631+
}
1632+
}
1633+
}
1634+
}
1635+
}
1636+
16321637
class Http2ClientResponse extends Http2Incoming {
16331638
constructor(stream, headers, options) {
16341639
super(stream, headers, options);

0 commit comments

Comments
 (0)