middleware/whoami: add (#264)

Add a new middleware that tells you who you are; IP, port and transport
is echoed back.

Also some various cleanup and documentation improvements while at it:

* ResponseWriter: improve the documentation of these helper functions.
* And add an NextHandler for use in tests. Make chaos_test.go and
* whoam_test.go use it.
This commit is contained in:
Miek Gieben 2016-09-17 17:09:05 +01:00 committed by GitHub
parent ed907d3327
commit 30fd224504
10 changed files with 219 additions and 10 deletions

View file

@ -224,6 +224,7 @@ func Section(t *testing.T, tc Case, sect Sect, rr []dns.RR) bool {
return true
}
// ErrorHanlder returns a Handler that returns ServerFailure error when called.
func ErrorHandler() Handler {
return HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
m := new(dns.Msg)
@ -233,7 +234,14 @@ func ErrorHandler() Handler {
})
}
// Copied here to prevent an import cycle.
// NextHandler returns a Handler that returns rcode and err.
func NextHandler(rcode int, err error) Handler {
return HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
return rcode, err
})
}
// Copied here to prevent an import cycle, so that we can define to above handlers.
type (
// HandlerFunc is a convenience type like dns.HandlerFunc, except
// ServeDNS returns an rcode and an error.