1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00

Rename RemoteIP to RealIP

This commit is contained in:
ipfans 2016-08-18 09:26:58 +08:00
parent 649a1e7885
commit 0b7959a57d
6 changed files with 9 additions and 17 deletions

View File

@ -68,8 +68,8 @@ type (
// RemoteAddress returns the client's network address.
RemoteAddress() string
// RemoteIP returns the client's network ip address.
RemoteIP() string
// RealIP returns the client's network ip address.
RealIP() string
// Method returns the request's HTTP function.
Method() string

View File

@ -79,8 +79,8 @@ func (r *Request) RemoteAddress() string {
return r.RemoteAddr().String()
}
// RemoteIP implements `engine.Request#RemoteIP` function.
func (r *Request) RemoteIP() string {
// RealIP implements `engine.Request#RealIP` function.
func (r *Request) RealIP() string {
ra := r.RemoteAddress()
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
ra = ip

View File

@ -99,8 +99,8 @@ func (r *Request) RemoteAddress() string {
return r.RemoteAddr
}
// RemoteIP implements `engine.Request#RemoteIP` function.
func (r *Request) RemoteIP() string {
// RealIP implements `engine.Request#RealIP` function.
func (r *Request) RealIP() string {
ra := r.RemoteAddress()
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
ra = ip

View File

@ -51,7 +51,7 @@ func RequestTest(t *testing.T, request engine.Request) {
assert.Equal(t, "http", request.Scheme())
assert.Equal(t, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10", request.UserAgent())
assert.Equal(t, "127.0.0.1", request.RemoteAddress())
assert.Equal(t, "192.168.1.1", request.RemoteIP())
assert.Equal(t, "192.168.1.1", request.RealIP())
assert.Equal(t, "POST", request.Method())
assert.Equal(t, int64(261), request.ContentLength())

View File

@ -3,7 +3,6 @@ package middleware
import (
"bytes"
"io"
"net"
"os"
"strconv"
"sync"
@ -118,14 +117,7 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
case "time_rfc3339":
return w.Write([]byte(time.Now().Format(time.RFC3339)))
case "remote_ip":
ra := req.RemoteAddress()
if ip := req.Header().Get(echo.HeaderXRealIP); ip != "" {
ra = ip
} else if ip = req.Header().Get(echo.HeaderXForwardedFor); ip != "" {
ra = ip
} else {
ra, _, _ = net.SplitHostPort(ra)
}
ra := req.RealIP()
return w.Write([]byte(ra))
case "host":
return w.Write([]byte(req.Host()))

View File

@ -86,7 +86,7 @@ func (r *Request) RemoteAddress() string {
return r.request.RemoteAddr
}
func (r *Request) RemoteIP() string {
func (r *Request) RealIP() string {
ra := r.RemoteAddress()
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
ra = ip