mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 18:23:25 -05:00
Use context.Context
Rename the old Context to State and use context.Context in the middleware for intra-middleware communication and more.
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
package rewrite
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
/*
|
||||
func TestConditions(t *testing.T) {
|
||||
tests := []struct {
|
||||
condition string
|
||||
@@ -104,3 +99,4 @@ func TestConditions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ package rewrite
|
||||
import (
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/dns"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Result is the result of a rewrite
|
||||
@@ -27,12 +28,12 @@ type Rewrite struct {
|
||||
}
|
||||
|
||||
// ServeHTTP implements the middleware.Handler interface.
|
||||
func (rw Rewrite) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
wr := NewResponseReverter(w, r)
|
||||
for _, rule := range rw.Rules {
|
||||
switch result := rule.Rewrite(r); result {
|
||||
case RewriteDone:
|
||||
return rw.Next.ServeDNS(wr, r)
|
||||
return rw.Next.ServeDNS(ctx, wr, r)
|
||||
case RewriteIgnored:
|
||||
break
|
||||
case RewriteStatus:
|
||||
@@ -42,7 +43,7 @@ func (rw Rewrite) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
// }
|
||||
}
|
||||
}
|
||||
return rw.Next.ServeDNS(w, r)
|
||||
return rw.Next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
|
||||
// Rule describes an internal location rewrite rule.
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
package rewrite
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
)
|
||||
|
||||
/*
|
||||
func TestRewrite(t *testing.T) {
|
||||
rw := Rewrite{
|
||||
Next: middleware.HandlerFunc(urlPrinter),
|
||||
@@ -157,3 +148,4 @@ func urlPrinter(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
fmt.Fprintf(w, r.URL.String())
|
||||
return 0, nil
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user