diff options
author | 2016-03-19 19:56:58 +0000 | |
---|---|---|
committer | 2016-03-19 19:56:58 +0000 | |
commit | 6f5fe26e1f7105b732ffa4b750c782f9f02175ba (patch) | |
tree | 2d5bcdcbeb3997999a6e14adfd62f62633fe2289 /middleware.md | |
parent | 33f00b5a3a70839670178d4e3c60e642067a16f4 (diff) | |
download | coredns-6f5fe26e1f7105b732ffa4b750c782f9f02175ba.tar.gz coredns-6f5fe26e1f7105b732ffa4b750c782f9f02175ba.tar.zst coredns-6f5fe26e1f7105b732ffa4b750c782f9f02175ba.zip |
Add document detailing how the return code works for middleware
Diffstat (limited to 'middleware.md')
-rw-r--r-- | middleware.md | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/middleware.md b/middleware.md new file mode 100644 index 000000000..323eb15f5 --- /dev/null +++ b/middleware.md @@ -0,0 +1,22 @@ +# Writing middleware + +From the Caddy docs: + +> Oh yes, those pesky return values on ServeHTTP(). You read the documentation so you already know +> what they mean. But what does that imply for the behavior of your middleware? +> +> Basically, return a status code only if you did NOT write to the response body. If you DO write to +> the response body, return a status code of 0. Return an error value if your middleware encountered +> an error that you want logged. It is common to return an error status and an error value together, +> so that the error handler up the chain can write the correct error page. +> +> The returned status code is not logged directly; rather, it tells middleware higher up the chain +> what status code to use if/when the response body is written. Again, return a 0 status if you've +> already written a body! + +In the DNS status codes are called rcodes and it's slightly harder to return the correct +answer in case of failure. + +So CoreDNS treats only SERVFAIL (dns.RcodeServerFailure) as special and will then assume +nothing has written to the client. In all other cases it is assume something has been written +to the client. |