mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 18:53:43 -04:00
plugin/rewrite: use request.Request and other cleanups (#1920)
This was done anyway, but only deep in the functions, just do this everywhere; allows for shorter code and request.Request allows for caching as well. Cleanups, make it more Go like. * remove unneeded switches * remove testdir (why was this there??) * simplify the logic * remove unneeded variables * put short functions on a single line * fix documentation. * spin off wire funcs in wire.go, make them functions. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
@@ -38,8 +39,10 @@ type Rewrite struct {
|
||||
// ServeDNS implements the plugin.Handler interface.
|
||||
func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
wr := NewResponseReverter(w, r)
|
||||
state := request.Request{W: w, Req: r}
|
||||
|
||||
for _, rule := range rw.Rules {
|
||||
switch result := rule.Rewrite(w, r); result {
|
||||
switch result := rule.Rewrite(state); result {
|
||||
case RewriteDone:
|
||||
respRule := rule.GetResponseRule()
|
||||
if respRule.Active == true {
|
||||
@@ -68,7 +71,7 @@ func (rw Rewrite) Name() string { return "rewrite" }
|
||||
// Rule describes a rewrite rule.
|
||||
type Rule interface {
|
||||
// Rewrite rewrites the current request.
|
||||
Rewrite(dns.ResponseWriter, *dns.Msg) Result
|
||||
Rewrite(state request.Request) Result
|
||||
// Mode returns the processing mode stop or continue.
|
||||
Mode() string
|
||||
// GetResponseRule returns the rule to rewrite response with, if any.
|
||||
|
||||
Reference in New Issue
Block a user