diff options
author | Wolfy-J <[email protected]> | 2018-07-08 20:13:30 -0700 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-07-08 20:13:30 -0700 |
commit | 3ef9d686381e6f888c32c707c4ed245cb546506f (patch) | |
tree | d7fceee70976bfb7a9f495bbabef0373ecc214fe /service | |
parent | 78c4f250ba81266eab64288d44cf91b85ad00ba9 (diff) |
remote IP
Diffstat (limited to 'service')
-rw-r--r-- | service/container.go | 2 | ||||
-rw-r--r-- | service/http/request.go | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/service/container.go b/service/container.go index a003b7e3..02ebbf26 100644 --- a/service/container.go +++ b/service/container.go @@ -158,7 +158,7 @@ func (c *container) Serve() error { continue } - c.log.Debugf("[%s]: started", e.name) + c.log.Debugf("[%s]: service started", e.name) go func(e *entry) { e.setStatus(StatusServing) defer e.setStatus(StatusStopped) 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 |