Skip to content

Commit e564dd0

Browse files
committed
Bumped v0.7.2
Signed-off-by: Vishal Rana <[email protected]>
1 parent e12fd1e commit e564dd0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cube.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,15 @@ func (c *Cube) dispatch() error {
111111
// Start starts recording an HTTP request.
112112
func (c *Cube) Start(r *http.Request, w http.ResponseWriter) (request *CubeRequest) {
113113
request = &CubeRequest{
114+
ID: RequestID(r, w),
114115
Time: time.Now(),
115116
AppID: c.AppID,
116117
AppName: c.AppName,
117118
Host: r.Host,
118119
Path: r.URL.Path,
119120
Method: r.Method,
120121
UserAgent: r.UserAgent(),
121-
RemoteIP: realIP(r),
122+
RemoteIP: RealIP(r),
122123
}
123124
request.ClientID = request.RemoteIP
124125
atomic.AddInt64(&c.activeRequests, 1)

util.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ const (
1111
rfc3339Micro = "2006-01-02T15:04:05.000000Z07:00"
1212
)
1313

14-
func realIP(r *http.Request) string {
14+
// RequestID returns the request ID from the request or response.
15+
func RequestID(r *http.Request, w http.ResponseWriter) string {
16+
id := r.Header.Get("X-Request-ID")
17+
if id == "" {
18+
id = w.Header().Get("X-Request-ID")
19+
}
20+
return id
21+
}
22+
23+
// RealIP returns the real IP from the request.
24+
func RealIP(r *http.Request) string {
1525
ra := r.RemoteAddr
1626
if ip := r.Header.Get("X-Forwarded-For"); ip != "" {
1727
ra = strings.Split(ip, ", ")[0]

0 commit comments

Comments
 (0)