Documentation ¶
Overview ¶
Package middleware provides some types and functions common among middleware.
Index ¶
- Constants
- func Edns0Version(req *dns.Msg) (*dns.Msg, error)
- func Exchange(c *dns.Client, m *dns.Msg, server string) (*dns.Msg, error)
- func Less(a, b string) int
- func Proto(w dns.ResponseWriter) string
- func RcodeToString(rcode int) string
- func SplitCommandAndArgs(command string) (cmd string, args []string, err error)
- type Addr
- type Handler
- type HandlerFunc
- type Host
- type LogRoller
- type Middleware
- type MsgType
- type Name
- type Replacer
- type ResponseRecorder
- func (r *ResponseRecorder) Hijack()
- func (r *ResponseRecorder) Msg() *dns.Msg
- func (r *ResponseRecorder) Rcode() string
- func (r *ResponseRecorder) Size() int
- func (r *ResponseRecorder) Start() time.Time
- func (r *ResponseRecorder) Write(buf []byte) (int, error)
- func (r *ResponseRecorder) WriteMsg(res *dns.Msg) error
- type Result
- type State
- func (s *State) Class() string
- func (s *State) Clear()
- func (s *State) Do() bool
- func (s *State) ErrorMessage(rcode int) *dns.Msg
- func (s *State) Family() int
- func (s *State) IP() string
- func (s *State) Name() string
- func (s *State) Now(format string) string
- func (s *State) NowDate() time.Time
- func (s *State) Port() (string, error)
- func (s *State) Proto() string
- func (s *State) QClass() uint16
- func (s *State) QName() string
- func (s *State) QType() uint16
- func (s *State) RemoteAddr() string
- func (s *State) Scrub(reply *dns.Msg) (*dns.Msg, Result)
- func (s *State) Size() int
- func (s *State) SizeAndDo(m *dns.Msg) bool
- func (s *State) Type() string
- type Zones
Examples ¶
Constants ¶
const Namespace = "coredns"
Variables ¶
This section is empty.
Functions ¶
func Edns0Version ¶
Edns0Version checks the EDNS version in the request. If error is nil everything is OK and we can invoke the middleware. If non-nil, the returned Msg is valid to be returned to the client (and should). For some reason this response should not contain a question RR in the question section.
func Less ¶
Less returns <0 when a is less than b, 0 when they are equal and >0 when a is larger than b. The function orders names in DNSSEC canonical order: RFC 4034s section-6.1
See http://bert-hubert.blogspot.co.uk/2015/10/how-to-do-fast-canonical-ordering-of.html for a blog article on this implementation.
The values of a and b are *not* lowercased before the comparison!
func Proto ¶
func Proto(w dns.ResponseWriter) string
Proto gets the protocol used as the transport. This will be udp or tcp.
func RcodeToString ¶
func SplitCommandAndArgs ¶
SplitCommandAndArgs takes a command string and parses it shell-style into the command and its separate arguments.
Example ¶
var commandLine string var command string var args []string // just for the test - change GOOS and reset it at the end of the test runtimeGoos = "windows" defer func() { runtimeGoos = runtime.GOOS }() commandLine = `mkdir /P "C:\Program Files"` command, args, _ = SplitCommandAndArgs(commandLine) fmt.Printf("Windows: %s: %s [%s]\n", commandLine, command, strings.Join(args, ",")) // set GOOS to linux runtimeGoos = "linux" commandLine = `mkdir -p /path/with\ space` command, args, _ = SplitCommandAndArgs(commandLine) fmt.Printf("Linux: %s: %s [%s]\n", commandLine, command, strings.Join(args, ","))
Output: Windows: mkdir /P "C:\Program Files": mkdir [/P,C:\Program Files] Linux: mkdir -p /path/with\ space: mkdir [-p,/path/with space]
Types ¶
type Handler ¶
Handler is like dns.Handler except ServeDNS may return an rcode and/or error.
If ServeDNS writes to the response body, it should return a status code. If the status code is not one of the following: * SERVFAIL (dns.RcodeServerFailure) * REFUSED (dns.RecodeRefused) * FORMERR (dns.RcodeFormatError) * NOTIMP (dns.RcodeNotImplemented)
CoreDNS assumes *no* reply has yet been written. All other response codes signal other handlers above it that the response message is already written, and that they should not write to it also.
If ServeDNS encounters an error, it should return the error value so it can be logged by designated error-handling middleware.
If writing a response after calling another ServeDNS method, the returned rcode SHOULD be used when writing the response.
If handling errors after calling another ServeDNS method, the returned error value SHOULD be logged or handled accordingly.
Otherwise, return values should be propagated down the middleware chain by returning them unchanged.
type HandlerFunc ¶
HandlerFunc is a convenience type like dns.HandlerFunc, except ServeDNS returns an rcode and an error. See Handler documentation for more information.
type LogRoller ¶
LogRoller implements a middleware that provides a rolling logger.
func (LogRoller) GetLogWriter ¶
GetLogWriter returns an io.Writer that writes to a rolling logger.
type Middleware ¶
Middleware is the middle layer which represents the traditional idea of middleware: it chains one Handler to the next by being passed the next Handler in the chain.
type Name ¶
type Name string
Name represents a domain name.
type Replacer ¶
Replacer is a type which can replace placeholder substrings in a string with actual values from a dns.Msg and responseRecorder. Always use NewReplacer to get one of these.
func NewReplacer ¶
func NewReplacer(r *dns.Msg, rr *ResponseRecorder, emptyValue string) Replacer
NewReplacer makes a new replacer based on r and rr. Do not create a new replacer until r and rr have all the needed values, because this function copies those values into the replacer. rr may be nil if it is not available. emptyValue should be the string that is used in place of empty string (can still be empty string).
type ResponseRecorder ¶
type ResponseRecorder struct { dns.ResponseWriter // contains filtered or unexported fields }
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.
func NewResponseRecorder ¶
func NewResponseRecorder(w dns.ResponseWriter) *ResponseRecorder
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 (*ResponseRecorder) Hijack ¶
func (r *ResponseRecorder) Hijack()
Hijack implements dns.Hijacker. It simply wraps the underlying ResponseWriter's Hijack method if there is one, or returns an error.
func (*ResponseRecorder) Msg ¶
func (r *ResponseRecorder) Msg() *dns.Msg
Msg returns the written message from the ResponseRecorder.
func (*ResponseRecorder) Start ¶
func (r *ResponseRecorder) Start() time.Time
Start returns the start time of the ResponseRecorder.
type State ¶
type State struct { Req *dns.Msg W dns.ResponseWriter // contains filtered or unexported fields }
State contains some connection state and is useful in middleware.
func (*State) ErrorMessage ¶
ErrorMessage returns an error message suitable for sending back to the client.
func (*State) Name ¶
Name returns the name of the question in the request. Note this name will always have a closing dot and will be lower cased. After a call Name the value will be cached. To clear this caching call Clear.
func (*State) NowDate ¶
NowDate returns the current date/time that can be used in other time functions.
func (*State) RemoteAddr ¶
RemoteAddr returns the net.Addr of the client that sent the current request.
func (*State) Scrub ¶
Scrub scrubs the reply message so that it will fit the client's buffer. If even after dropping the additional section, it still does not fit the TC bit will be set on the message. Note, the TC bit will be set regardless of protocol, even TCP message will get the bit, the client should then retry with pigeons. TODO(referral).
func (*State) Size ¶
UDPSize returns if UDP buffer size advertised in the requests OPT record. Or when the request was over TCP, we return the maximum allowed size of 64K.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package errors implements an HTTP error handling middleware.
|
Package errors implements an HTTP error handling middleware. |
Package etcd provides the etcd backend.
|
Package etcd provides the etcd backend. |
tree
Package tree implements Left-Leaning Red Black trees as described by Robert Sedgewick.
|
Package tree implements Left-Leaning Red Black trees as described by Robert Sedgewick. |
Package kubernetes provides the kubernetes backend.
|
Package kubernetes provides the kubernetes backend. |
util
Package kubernetes/util provides helper functions for the kubernetes middleware
|
Package kubernetes/util provides helper functions for the kubernetes middleware |
Package loadbalance is middleware for rewriting responses to do "load balancing"
|
Package loadbalance is middleware for rewriting responses to do "load balancing" |
Package log implements basic but useful request (access) logging middleware.
|
Package log implements basic but useful request (access) logging middleware. |
Package proxy is middleware that proxies requests.
|
Package proxy is middleware that proxies requests. |
Package rewrite is middleware for rewriting requests internally to something different.
|
Package rewrite is middleware for rewriting requests internally to something different. |
Package singleflight provides a duplicate function call suppression mechanism.
|
Package singleflight provides a duplicate function call suppression mechanism. |