2017-02-07 16:53:16 -05:00
|
|
|
package rewrite
|
|
|
|
|
|
|
|
|
|
import (
|
2017-02-21 22:51:47 -08:00
|
|
|
"github.com/coredns/coredns/middleware"
|
2017-03-06 16:32:17 -05:00
|
|
|
|
2017-02-07 16:53:16 -05:00
|
|
|
"github.com/miekg/dns"
|
|
|
|
|
)
|
|
|
|
|
|
2017-03-06 16:32:17 -05:00
|
|
|
type nameRule struct {
|
2017-02-07 16:53:16 -05:00
|
|
|
From, To string
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 16:32:17 -05:00
|
|
|
func newNameRule(from, to string) (Rule, error) {
|
|
|
|
|
return &nameRule{middleware.Name(from).Normalize(), middleware.Name(to).Normalize()}, nil
|
2017-02-07 16:53:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rewrite rewrites the the current request.
|
2017-08-24 09:34:07 -07:00
|
|
|
func (rule *nameRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
|
2017-02-07 16:53:16 -05:00
|
|
|
if rule.From == r.Question[0].Name {
|
|
|
|
|
r.Question[0].Name = rule.To
|
|
|
|
|
return RewriteDone
|
|
|
|
|
}
|
|
|
|
|
return RewriteIgnored
|
|
|
|
|
}
|