* Remove context.Context from request.Request This removes the context from request.Request and makes all the changes in the code to make it compile again. It's all mechanical. It did unearth some weirdness in that the context was kept in handler structs which may cause havoc with concurrently handling of requests. Fixes #2721 Signed-off-by: Miek Gieben <miek@miek.nl> * Make test compile Signed-off-by: Miek Gieben <miek@miek.nl>
36 lines
977 B
Go
36 lines
977 B
Go
// Package upstream abstracts a upstream lookups so that plugins can handle them in an unified way.
|
|
package upstream
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"github.com/coredns/coredns/core/dnsserver"
|
|
"github.com/coredns/coredns/plugin/pkg/nonwriter"
|
|
"github.com/coredns/coredns/request"
|
|
)
|
|
|
|
// Upstream is used to resolve CNAME or other external targets via CoreDNS itself.
|
|
type Upstream struct{}
|
|
|
|
// New creates a new Upstream to resolve names using the coredns process.
|
|
func New() *Upstream { return &Upstream{} }
|
|
|
|
// Lookup routes lookups to our selves or forward to a remote.
|
|
func (u *Upstream) Lookup(ctx context.Context, state request.Request, name string, typ uint16) (*dns.Msg, error) {
|
|
server, ok := ctx.Value(dnsserver.Key{}).(*dnsserver.Server)
|
|
if !ok {
|
|
return nil, fmt.Errorf("no full server is running")
|
|
}
|
|
|
|
req := new(dns.Msg)
|
|
req.SetQuestion(name, typ)
|
|
|
|
nw := nonwriter.New(state.W)
|
|
|
|
server.ServeDNS(ctx, nw, req)
|
|
|
|
return nw.Msg, nil
|
|
}
|