Expose some tls functions from the proxy for use elsewhere.

This commit is contained in:
Tom Wilkie committed 2015-10-13 14:56:11 +00:00
1 parent 827bcd898e
commit 5b8ce8ebae
2 files changed
+7 -5

No files matched your search

+2 -2
View File
@@ -76,7 +76,7 @@ type Proxy struct {
func NewProxy(c Config) (*Proxy, error) {
p := &Proxy{Config: c, waiters: make(map[*http.Request]*wait)}
if err := p.TLSConfig.loadCerts(); err != nil {
if err := p.TLSConfig.LoadCerts(); err != nil {
Log.Fatalf("Could not configure tls for proxy: %s", err)
}
@@ -262,7 +262,7 @@ func (proxy *Proxy) listen(protoAndAddr string) (net.Listener, string, error) {
if err != nil {
return nil, "", err
}
if proxy.TLSConfig.enabled() {
if proxy.TLSConfig.IsEnabled() {
listener = tls.NewListener(listener, proxy.TLSConfig.Config)
}
+5 -3
View File
@@ -17,15 +17,17 @@ type TLSConfig struct {
*tls.Config
}
func (c *TLSConfig) enabled() bool {
// IsEnabled returns true if TLS is enable, according to the config.
func (c *TLSConfig) IsEnabled() bool {
if c == nil {
return false
}
return c.Enabled || c.Verify
}
func (c *TLSConfig) loadCerts() error {
if !c.enabled() {
// LoadCerts loads the certificates into c.Config, if TLS is enabled.
func (c *TLSConfig) LoadCerts() error {
if !c.IsEnabled() {
return nil
}