aboutsummaryrefslogtreecommitdiff
path: root/request
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-07-02 15:39:50 +0100
committerGravatar Yong Tang <yong.tang.github@outlook.com> 2018-07-02 07:39:50 -0700
commit6dd2cf8c4b30822f1d718fbef728f6856628a3df (patch)
treefce20dc6ee9a9400130c0c82292ba470be82fe7b /request
parent1abecf99d97270075731b9f7cc01c9e2b687d570 (diff)
downloadcoredns-6dd2cf8c4b30822f1d718fbef728f6856628a3df.tar.gz
coredns-6dd2cf8c4b30822f1d718fbef728f6856628a3df.tar.zst
coredns-6dd2cf8c4b30822f1d718fbef728f6856628a3df.zip
plugin/rewrite: use request.Request and other cleanups (#1920)
This was done anyway, but only deep in the functions, just do this everywhere; allows for shorter code and request.Request allows for caching as well. Cleanups, make it more Go like. * remove unneeded switches * remove testdir (why was this there??) * simplify the logic * remove unneeded variables * put short functions on a single line * fix documentation. * spin off wire funcs in wire.go, make them functions. Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'request')
-rw-r--r--request/request.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/request/request.go b/request/request.go
index 88a92405f..36ec85731 100644
--- a/request/request.go
+++ b/request/request.go
@@ -59,6 +59,15 @@ func (r *Request) IP() string {
return r.ip
}
+// LocalIP gets the (local) IP address of server handling the request.
+func (r *Request) LocalIP() string {
+ ip, _, err := net.SplitHostPort(r.W.LocalAddr().String())
+ if err != nil {
+ return r.W.LocalAddr().String()
+ }
+ return ip
+}
+
// Port gets the (remote) port of the client making the request.
func (r *Request) Port() string {
if r.port != "" {