summaryrefslogtreecommitdiff
path: root/service/http/request.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-08 20:13:30 -0700
committerWolfy-J <[email protected]>2018-07-08 20:13:30 -0700
commit3ef9d686381e6f888c32c707c4ed245cb546506f (patch)
treed7fceee70976bfb7a9f495bbabef0373ecc214fe /service/http/request.go
parent78c4f250ba81266eab64288d44cf91b85ad00ba9 (diff)
remote IP
Diffstat (limited to 'service/http/request.go')
-rw-r--r--service/http/request.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/service/http/request.go b/service/http/request.go
index 912843e9..08e2a03e 100644
--- a/service/http/request.go
+++ b/service/http/request.go
@@ -9,6 +9,7 @@ import (
"net/url"
"strings"
"github.com/spiral/roadrunner/service/http/attributes"
+ "net"
)
const (
@@ -21,6 +22,9 @@ const (
// Request maps net/http requests to PSR7 compatible structure and managed state of temporary uploaded files.
type Request struct {
+ // RemoteAddr contains ip address of client, make sure to check X-Real-Ip and X-Forwarded-For for real client address.
+ RemoteAddr string `json:"remoteAddr"`
+
// Protocol includes HTTP protocol version.
Protocol string `json:"protocol"`
@@ -64,6 +68,13 @@ func NewRequest(r *http.Request, cfg *UploadsConfig) (req *Request, err error) {
Attributes: attributes.All(r),
}
+ // otherwise, return remote address as is
+ if strings.ContainsRune(r.RemoteAddr, ':') {
+ req.RemoteAddr, _, _ = net.SplitHostPort(r.RemoteAddr)
+ } else {
+ req.RemoteAddr = r.RemoteAddr
+ }
+
for _, c := range r.Cookies() {
if v, err := url.QueryUnescape(c.Value); err == nil {
req.Cookies[c.Name] = v