@@ -32,11 +32,12 @@ func init() {
32
32
caddytls .RegisterConfigGetter (serverType , func (c * caddy.Controller ) * caddytls.Config { return GetConfig (c ).TLS })
33
33
}
34
34
35
- func newContext () caddy.Context {
36
- return & netContext {keysToConfigs : make (map [string ]* Config )}
35
+ func newContext (inst * caddy. Instance ) caddy.Context {
36
+ return & netContext {instance : inst , keysToConfigs : make (map [string ]* Config )}
37
37
}
38
38
39
39
type netContext struct {
40
+ instance * caddy.Instance
40
41
// keysToConfigs maps an address at the top of a
41
42
// server block (a "key") to its Config. Not all
42
43
// Configs will be represented here, only ones
@@ -109,9 +110,14 @@ func (n *netContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
109
110
if listenType == "proxy" && len (params ) < 2 {
110
111
return serverBlocks , fmt .Errorf ("invalid configuration: proxy server block expects a source and destination address" )
111
112
}
113
+
114
+ // Make our caddytls.Config, which has a pointer to the
115
+ // instance's certificate cache
116
+ caddytlsConfig := caddytls .NewConfig (n .instance )
117
+
112
118
// Save the config to our master list, and key it for lookups
113
119
c := & Config {
114
- TLS : & caddytls. Config {} ,
120
+ TLS : caddytlsConfig ,
115
121
Type : listenType ,
116
122
ListenPort : params [0 ], // first element should always be the port
117
123
Parameters : params ,
@@ -153,12 +159,12 @@ func (n *netContext) MakeServers() ([]caddy.Server, error) {
153
159
// new, empty one will be created.
154
160
func GetConfig (c * caddy.Controller ) * Config {
155
161
ctx := c .Context ().(* netContext )
156
- key := strings .ToLower (c .Key )
162
+ key := strings .Join (c .ServerBlockKeys , "~" )
157
163
158
164
//only check for config if the value is proxy or echo
159
165
//we need to do this because we specify the ports in the server block
160
166
//and those values need to be ignored as they are also sent from caddy main process.
161
- if key == "echo" || key == "proxy" {
167
+ if strings . Contains ( key , "echo" ) || strings . Contains ( key , "proxy" ) {
162
168
if cfg , ok := ctx .keysToConfigs [key ]; ok {
163
169
return cfg
164
170
}
@@ -168,5 +174,7 @@ func GetConfig(c *caddy.Controller) *Config {
168
174
// is not echo or proxy i.e port number :12017
169
175
// we can't return a nil because caddytls.RegisterConfigGetter will panic
170
176
// so we return a default (blank) config value
171
- return & Config {TLS : new (caddytls.Config )}
177
+ caddytlsConfig := caddytls .NewConfig (ctx .instance )
178
+
179
+ return & Config {TLS : caddytlsConfig }
172
180
}
0 commit comments