mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 10:43:17 -04: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:
@@ -7,6 +7,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
@@ -67,7 +69,7 @@ func (uh *UpstreamHost) Down() bool {
|
||||
var tryDuration = 60 * time.Second
|
||||
|
||||
// ServeDNS satisfies the middleware.Handler interface.
|
||||
func (p Proxy) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
for _, upstream := range p.Upstreams {
|
||||
// allowed bla bla bla TODO(miek): fix full proxy spec from caddy
|
||||
start := time.Now()
|
||||
@@ -100,7 +102,7 @@ func (p Proxy) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
}
|
||||
return dns.RcodeServerFailure, errUnreachable
|
||||
}
|
||||
return p.Next.ServeDNS(w, r)
|
||||
return p.Next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
|
||||
func Clients() Client {
|
||||
|
||||
@@ -1,26 +1,6 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
/*
|
||||
func init() {
|
||||
tryDuration = 50 * time.Millisecond // prevent tests from hanging
|
||||
}
|
||||
@@ -315,3 +295,4 @@ func (c *fakeConn) SetWriteDeadline(t time.Time) error { return nil }
|
||||
func (c *fakeConn) Close() error { return nil }
|
||||
func (c *fakeConn) Read(b []byte) (int, error) { return c.readBuf.Read(b) }
|
||||
func (c *fakeConn) Write(b []byte) (int, error) { return c.writeBuf.Write(b) }
|
||||
*/
|
||||
|
||||
@@ -12,15 +12,15 @@ type ReverseProxy struct {
|
||||
}
|
||||
|
||||
func (p ReverseProxy) ServeDNS(w dns.ResponseWriter, r *dns.Msg, extra []dns.RR) error {
|
||||
// TODO(miek): use extra!
|
||||
// TODO(miek): use extra to EDNS0.
|
||||
var (
|
||||
reply *dns.Msg
|
||||
err error
|
||||
)
|
||||
context := middleware.Context{W: w, Req: r}
|
||||
state := middleware.State{W: w, Req: r}
|
||||
|
||||
// tls+tcp ?
|
||||
if context.Proto() == "tcp" {
|
||||
if state.Proto() == "tcp" {
|
||||
reply, err = middleware.Exchange(p.Client.TCP, r, p.Host)
|
||||
} else {
|
||||
reply, err = middleware.Exchange(p.Client.UDP, r, p.Host)
|
||||
|
||||
Reference in New Issue
Block a user