@@ -152,9 +152,9 @@ will create a new session. See [RFC 2246][] for more information, page 23 and
152
152
Resumption using session identifiers is supported by most web browsers when
153
153
making HTTPS requests.
154
154
155
- For Node.js, clients must call [ ` tls.TLSSocket.getSession() ` ] [ ] after the
156
- [ ` 'secureConnect' ` ] [ ] event to get the session data, and provide the data to the
157
- ` session ` option of [ ` tls.connect() ` ] [ ] to reuse the session. Servers must
155
+ For Node.js, clients wait for the [ ` 'session' ` ] [ ] event to get the session data,
156
+ and provide the data to the ` session ` option of a subsequent [ ` tls.connect() ` ] [ ]
157
+ to reuse the session. Servers must
158
158
implement handlers for the [ ` 'newSession' ` ] [ ] and [ ` 'resumeSession' ` ] [ ] events
159
159
to save and restore the session data using the session ID as the lookup key to
160
160
reuse sessions. To reuse sessions across load balancers or cluster workers,
@@ -614,6 +614,45 @@ determine if the server certificate was signed by one of the specified CAs. If
614
614
` tlsSocket.alpnProtocol ` property can be checked to determine the negotiated
615
615
protocol.
616
616
617
+ ### Event: 'session'
618
+ <!-- YAML
619
+ added: REPLACEME
620
+ -->
621
+
622
+ * ` session ` {Buffer}
623
+
624
+ The ` 'session' ` event is emitted on a client ` tls.TLSSocket ` when a new session
625
+ or TLS ticket is available. This may or may not be before the handshake is
626
+ complete, depending on the TLS protocol version that was negotiated. The event
627
+ is not emitted on the server, or if a new session was not created, for example,
628
+ when the connection was resumed. For some TLS protocol versions the event may be
629
+ emitted multiple times, in which case all the sessions can be used for
630
+ resumption.
631
+
632
+ On the client, the ` session ` can be provided to the ` session ` option of
633
+ [ ` tls.connect() ` ] [ ] to resume the connection.
634
+
635
+ See [ Session Resumption] [ ] for more information.
636
+
637
+ Note: For TLS1.2 and below, [ ` tls.TLSSocket.getSession() ` ] [ ] can be called once
638
+ the handshake is complete. For TLS1.3, only ticket based resumption is allowed
639
+ by the protocol, multiple tickets are sent, and the tickets aren't sent until
640
+ later, after the handshake completes, so it is necessary to wait for the
641
+ ` 'session' ` event to get a resumable session. Future-proof applications are
642
+ recommended to use the ` 'session' ` event instead of ` getSession() ` to ensure
643
+ they will work for all TLS protocol versions. Applications that only expect to
644
+ get or use 1 session should listen for this event only once:
645
+
646
+ ``` js
647
+ tlsSocket .once (' session' , (session ) => {
648
+ // The session can be used immediately or later.
649
+ tls .connect ({
650
+ session: session,
651
+ // Other connect options...
652
+ });
653
+ });
654
+ ```
655
+
617
656
### tlsSocket.address()
618
657
<!-- YAML
619
658
added: v0.11.4
@@ -880,6 +919,9 @@ for debugging.
880
919
881
920
See [ Session Resumption] [ ] for more information.
882
921
922
+ Note: ` getSession() ` works only for TLS1.2 and below. Future-proof applications
923
+ should use the [ ` 'session' ` ] [ ] event.
924
+
883
925
### tlsSocket.getTLSTicket()
884
926
<!-- YAML
885
927
added: v0.11.4
@@ -1538,6 +1580,7 @@ where `secureSocket` has the same API as `pair.cleartext`.
1538
1580
[ `'resumeSession'` ] : #tls_event_resumesession
1539
1581
[ `'secureConnect'` ] : #tls_event_secureconnect
1540
1582
[ `'secureConnection'` ] : #tls_event_secureconnection
1583
+ [ `'session'` ] : #tls_event_session
1541
1584
[ `--tls-cipher-list` ] : cli.html#cli_tls_cipher_list_list
1542
1585
[ `NODE_OPTIONS` ] : cli.html#cli_node_options_options
1543
1586
[ `crypto.getCurves()` ] : crypto.html#crypto_crypto_getcurves
0 commit comments