Is there a way to Un-RegisterServerType?

Hi,

This sounds like a silly question at first…
Is there a way to undo a previous call to RegisterServerType(), i.e. assuming a call was made, can a later call to caddy be made to undo this registration? E.g. clear it back to default or otherwise make Caddy forget that the server was registered, e.g. to allow it to be modified or otherwise re-registered.
Or
Is there a way to modify the registered server type? Specifically to change its list of Directives?

I.e. we would have been satisfied if RegisterServerType could be called more than once and the latest call wins (right now calling for the second time results in “panic: server type already registered”)

Why do we need that?
As part of (Knative Security-Guard), we are looking to use part of CoreDNS which is built on top of Caddy. Our aim is to import "github.com/coredns/coredns/core/dnsserver" and then use it. I.e. we wish to register a server type named “DNS” and define our list of Directives.

Unfortunately, github.com/coredns/coredns/core/dnsserver uses init() to perform RegisterServerType() and registers Directives (which are the default for CoreDNS) before we ever get a chance to register our own.

We are trying to get the CoreDNS to change their code and not use init() but we are not sure if that will be accepted - e.g. if it affects others already relying on that init().

Thanks,
davidhadas

CoreDNS uses an old fork of Caddy v1, which they heavily stripped down to get rid of the rest of the code they didn’t need anymore.

We no longer maintain Caddy v1, and obviously we don’t maintain that fork, so we can’t help you with that.

My recommendation would be to write a Caddy 2 module instead. It will do exactly what you need, and even allows you to register your own server type. Here’s an example to get started: Extending Caddy — Caddy Documentation – this walks you through an HTTP handler, but you can write an “app” module just as well.

This topic was automatically closed after 60 days. New replies are no longer allowed.