Use only the ip part of request RemoteAddr

This commit is contained in:
Donn Pebe
2015-07-02 01:48:21 +07:00
parent 4cc2de6207
commit c1719f7e20
2 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"errors"
"io"
"math"
"net"
"net/http"
"strings"
"time"
@ -269,7 +270,10 @@ func (c *Context) ClientIP() string {
return clientIP
}
}
return strings.TrimSpace(c.Request.RemoteAddr)
if ip, _, err := net.SplitHostPort(strings.TrimSpace(c.Request.RemoteAddr)); err == nil {
return ip
}
return ""
}
func (c *Context) ContentType() string {