Skip to content

Commit afb7432

Browse files
authored
Merge pull request #7 from pieterlouw/issue5
Fix issue5 (request from upstream Caddy changes) as well as issue6 (TLS bug)
2 parents bb3a4ab + 2928011 commit afb7432

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

caddynet/netserver/plugin.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ func init() {
3232
caddytls.RegisterConfigGetter(serverType, func(c *caddy.Controller) *caddytls.Config { return GetConfig(c).TLS })
3333
}
3434

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)}
3737
}
3838

3939
type netContext struct {
40+
instance *caddy.Instance
4041
// keysToConfigs maps an address at the top of a
4142
// server block (a "key") to its Config. Not all
4243
// Configs will be represented here, only ones
@@ -109,9 +110,14 @@ func (n *netContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
109110
if listenType == "proxy" && len(params) < 2 {
110111
return serverBlocks, fmt.Errorf("invalid configuration: proxy server block expects a source and destination address")
111112
}
113+
114+
// Make our caddytls.Config, which has a pointer to the
115+
// instance's certificate cache
116+
caddytlsConfig := caddytls.NewConfig(n.instance)
117+
112118
// Save the config to our master list, and key it for lookups
113119
c := &Config{
114-
TLS: &caddytls.Config{},
120+
TLS: caddytlsConfig,
115121
Type: listenType,
116122
ListenPort: params[0], // first element should always be the port
117123
Parameters: params,
@@ -153,12 +159,12 @@ func (n *netContext) MakeServers() ([]caddy.Server, error) {
153159
// new, empty one will be created.
154160
func GetConfig(c *caddy.Controller) *Config {
155161
ctx := c.Context().(*netContext)
156-
key := strings.ToLower(c.Key)
162+
key := strings.Join(c.ServerBlockKeys, "~")
157163

158164
//only check for config if the value is proxy or echo
159165
//we need to do this because we specify the ports in the server block
160166
//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") {
162168
if cfg, ok := ctx.keysToConfigs[key]; ok {
163169
return cfg
164170
}
@@ -168,5 +174,7 @@ func GetConfig(c *caddy.Controller) *Config {
168174
// is not echo or proxy i.e port number :12017
169175
// we can't return a nil because caddytls.RegisterConfigGetter will panic
170176
// 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}
172180
}

0 commit comments

Comments
 (0)