diff options
author | 2016-09-07 11:10:16 +0100 | |
---|---|---|
committer | 2016-09-07 11:10:16 +0100 | |
commit | d1f17fa7e061d91aa0af7e1fb959a68db899c812 (patch) | |
tree | 0f828a0e7bd8ca86051a721dae48e8c19a0a2f0e /middleware/recorder.go | |
parent | 684330fd28f65a7a8d1ad01fb4c6c5db78240f29 (diff) | |
download | coredns-d1f17fa7e061d91aa0af7e1fb959a68db899c812.tar.gz coredns-d1f17fa7e061d91aa0af7e1fb959a68db899c812.tar.zst coredns-d1f17fa7e061d91aa0af7e1fb959a68db899c812.zip |
Cleanup: put middleware helper functions in pkgs (#245)
Move all (almost all) Go files in middleware into their
own packages. This makes for better naming and discoverability.
Lot of changes elsewhere to make this change.
The middleware.State was renamed to request.Request which is better,
but still does not cover all use-cases. It was also moved out middleware
because it is used by `dnsserver` as well.
A pkg/dnsutil packages was added for shared, handy, dns util functions.
All normalize functions are now put in normalize.go
Diffstat (limited to 'middleware/recorder.go')
-rw-r--r-- | middleware/recorder.go | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/middleware/recorder.go b/middleware/recorder.go deleted file mode 100644 index d1e466ec3..000000000 --- a/middleware/recorder.go +++ /dev/null @@ -1,72 +0,0 @@ -package middleware - -import ( - "time" - - "github.com/miekg/dns" -) - -// ResponseRecorder is a type of ResponseWriter that captures -// the rcode code written to it and also the size of the message -// written in the response. A rcode code does not have -// to be written, however, in which case 0 must be assumed. -// It is best to have the constructor initialize this type -// with that default status code. -type ResponseRecorder struct { - dns.ResponseWriter - rcode int - size int - msg *dns.Msg - start time.Time -} - -// NewResponseRecorder makes and returns a new responseRecorder, -// which captures the DNS rcode from the ResponseWriter -// and also the length of the response message written through it. -func NewResponseRecorder(w dns.ResponseWriter) *ResponseRecorder { - return &ResponseRecorder{ - ResponseWriter: w, - rcode: 0, - msg: nil, - start: time.Now(), - } -} - -// WriteMsg records the status code and calls the -// underlying ResponseWriter's WriteMsg method. -func (r *ResponseRecorder) WriteMsg(res *dns.Msg) error { - r.rcode = res.Rcode - // We may get called multiple times (axfr for instance). - // Save the last message, but add the sizes. - r.size += res.Len() - r.msg = res - return r.ResponseWriter.WriteMsg(res) -} - -// Write is a wrapper that records the size of the message that gets written. -func (r *ResponseRecorder) Write(buf []byte) (int, error) { - n, err := r.ResponseWriter.Write(buf) - if err == nil { - r.size += n - } - return n, err -} - -// Size returns the size. -func (r *ResponseRecorder) Size() int { return r.size } - -// Rcode returns the rcode. -func (r *ResponseRecorder) Rcode() string { return RcodeToString(r.rcode) } - -// Start returns the start time of the ResponseRecorder. -func (r *ResponseRecorder) Start() time.Time { return r.start } - -// Msg returns the written message from the ResponseRecorder. -func (r *ResponseRecorder) Msg() *dns.Msg { return r.msg } - -// Hijack implements dns.Hijacker. It simply wraps the underlying -// ResponseWriter's Hijack method if there is one, or returns an error. -func (r *ResponseRecorder) Hijack() { - r.ResponseWriter.Hijack() - return -} |