plugin/forward: init ClientSessionCache in tls.Config (#4108)

* plugin/forward: init ClientSessionCache in tls.Config

 - ClientSessionCache may speed up a TLS handshake in upcoming connections
   to the same TLS server

Signed-off-by: Ruslan Drozhdzh <rdrozhdzh@infoblox.com>

* add comment

Signed-off-by: Ruslan Drozhdzh <rdrozhdzh@infoblox.com>
This commit is contained in:
Ruslan Drozhdzh 2020-09-08 16:36:06 +03:00 committed by GitHub
parent ca43f845eb
commit 04af1c692c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
package forward package forward
import ( import (
"crypto/tls"
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
@ -117,6 +118,11 @@ func parseStanza(c *caddy.Controller) (*Forward, error) {
if f.tlsServerName != "" { if f.tlsServerName != "" {
f.tlsConfig.ServerName = f.tlsServerName f.tlsConfig.ServerName = f.tlsServerName
} }
// Initialize ClientSessionCache in tls.Config. This may speed up a TLS handshake
// in upcoming connections to the same TLS server.
f.tlsConfig.ClientSessionCache = tls.NewLRUClientSessionCache(len(f.proxies))
for i := range f.proxies { for i := range f.proxies {
// Only set this for proxies that need it. // Only set this for proxies that need it.
if transports[i] == transport.TLS { if transports[i] == transport.TLS {