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:
parent
649a1e7885
commit
0b7959a57d
@ -68,8 +68,8 @@ type (
|
|||||||
// RemoteAddress returns the client's network address.
|
// RemoteAddress returns the client's network address.
|
||||||
RemoteAddress() string
|
RemoteAddress() string
|
||||||
|
|
||||||
// RemoteIP returns the client's network ip address.
|
// RealIP returns the client's network ip address.
|
||||||
RemoteIP() string
|
RealIP() string
|
||||||
|
|
||||||
// Method returns the request's HTTP function.
|
// Method returns the request's HTTP function.
|
||||||
Method() string
|
Method() string
|
||||||
|
@ -79,8 +79,8 @@ func (r *Request) RemoteAddress() string {
|
|||||||
return r.RemoteAddr().String()
|
return r.RemoteAddr().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteIP implements `engine.Request#RemoteIP` function.
|
// RealIP implements `engine.Request#RealIP` function.
|
||||||
func (r *Request) RemoteIP() string {
|
func (r *Request) RealIP() string {
|
||||||
ra := r.RemoteAddress()
|
ra := r.RemoteAddress()
|
||||||
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
|
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
|
||||||
ra = ip
|
ra = ip
|
||||||
|
@ -99,8 +99,8 @@ func (r *Request) RemoteAddress() string {
|
|||||||
return r.RemoteAddr
|
return r.RemoteAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteIP implements `engine.Request#RemoteIP` function.
|
// RealIP implements `engine.Request#RealIP` function.
|
||||||
func (r *Request) RemoteIP() string {
|
func (r *Request) RealIP() string {
|
||||||
ra := r.RemoteAddress()
|
ra := r.RemoteAddress()
|
||||||
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
|
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
|
||||||
ra = ip
|
ra = ip
|
||||||
|
@ -51,7 +51,7 @@ func RequestTest(t *testing.T, request engine.Request) {
|
|||||||
assert.Equal(t, "http", request.Scheme())
|
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, "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, "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, "POST", request.Method())
|
||||||
|
|
||||||
assert.Equal(t, int64(261), request.ContentLength())
|
assert.Equal(t, int64(261), request.ContentLength())
|
||||||
|
@ -3,7 +3,6 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
@ -118,14 +117,7 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
|
|||||||
case "time_rfc3339":
|
case "time_rfc3339":
|
||||||
return w.Write([]byte(time.Now().Format(time.RFC3339)))
|
return w.Write([]byte(time.Now().Format(time.RFC3339)))
|
||||||
case "remote_ip":
|
case "remote_ip":
|
||||||
ra := req.RemoteAddress()
|
ra := req.RealIP()
|
||||||
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)
|
|
||||||
}
|
|
||||||
return w.Write([]byte(ra))
|
return w.Write([]byte(ra))
|
||||||
case "host":
|
case "host":
|
||||||
return w.Write([]byte(req.Host()))
|
return w.Write([]byte(req.Host()))
|
||||||
|
@ -86,7 +86,7 @@ func (r *Request) RemoteAddress() string {
|
|||||||
return r.request.RemoteAddr
|
return r.request.RemoteAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) RemoteIP() string {
|
func (r *Request) RealIP() string {
|
||||||
ra := r.RemoteAddress()
|
ra := r.RemoteAddress()
|
||||||
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
|
if ip := r.Header().Get(echo.HeaderXForwardedFor); ip != "" {
|
||||||
ra = ip
|
ra = ip
|
||||||
|
Loading…
Reference in New Issue
Block a user