mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	request: Add LocalAddr() and LocalPort() (#1907)
These are used in the rewrite plugin, makes sense to have a common place for them. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
		| @@ -47,7 +47,7 @@ func (r *Request) IP() string { | |||||||
| 	return ip | 	return ip | ||||||
| } | } | ||||||
|  |  | ||||||
| // Port gets the (remote) Port of the client making the request. | // Port gets the (remote) port of the client making the request. | ||||||
| func (r *Request) Port() string { | func (r *Request) Port() string { | ||||||
| 	_, port, err := net.SplitHostPort(r.W.RemoteAddr().String()) | 	_, port, err := net.SplitHostPort(r.W.RemoteAddr().String()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -56,11 +56,21 @@ func (r *Request) Port() string { | |||||||
| 	return port | 	return port | ||||||
| } | } | ||||||
|  |  | ||||||
| // RemoteAddr returns the net.Addr of the client that sent the current request. | // LocalPort gets the local port of the server handling the request. | ||||||
| func (r *Request) RemoteAddr() string { | func (r *Request) LocalPort() string { | ||||||
| 	return r.W.RemoteAddr().String() | 	_, port, err := net.SplitHostPort(r.W.LocalAddr().String()) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return "0" | ||||||
|  | 	} | ||||||
|  | 	return port | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // RemoteAddr returns the net.Addr of the client that sent the current request. | ||||||
|  | func (r *Request) RemoteAddr() string { return r.W.RemoteAddr().String() } | ||||||
|  |  | ||||||
|  | // LocalAddr returns the net.Addr of the server handling the current request. | ||||||
|  | func (r *Request) LocalAddr() string { return r.W.LocalAddr().String() } | ||||||
|  |  | ||||||
| // Proto gets the protocol used as the transport. This will be udp or tcp. | // Proto gets the protocol used as the transport. This will be udp or tcp. | ||||||
| func (r *Request) Proto() string { return Proto(r.W) } | func (r *Request) Proto() string { return Proto(r.W) } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user