forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_success.go
67 lines (56 loc) · 1.15 KB
/
handler_success.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"net/http"
"net/http/httputil"
"time"
"strings"
"runtime/pprof"
"github.com/gorilla/context"
)
type ContextKey int
const (
SessionData = 0
AuthHeaderValue = 1
)
type TykMiddleware struct {
Spec ApiSpec
Proxy *httputil.ReverseProxy
}
type SuccessHandler struct{
TykMiddleware
}
func (s SuccessHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if config.EnableAnalytics {
t := time.Now()
keyName := r.Header.Get(s.Spec.ApiDefinition.Auth.AuthHeaderName)
version := s.Spec.getVersionFromRequest(r)
if version == "" {
version = "Non Versioned"
}
if s.Spec.ApiDefinition.Proxy.StripListenPath {
r.URL.Path = strings.Replace(r.URL.Path, s.Spec.Proxy.ListenPath, "", 1)
}
thisRecord := AnalyticsRecord{
r.Method,
r.URL.Path,
r.ContentLength,
r.Header.Get("User-Agent"),
t.Day(),
t.Month(),
t.Year(),
t.Hour(),
200,
keyName,
t,
version,
s.Spec.ApiDefinition.Name,
s.Spec.ApiDefinition.ApiId,
s.Spec.ApiDefinition.OrgId}
analytics.RecordHit(thisRecord)
}
s.Proxy.ServeHTTP(w, r)
if doMemoryProfile {
pprof.WriteHeapProfile(prof_file)
}
context.Clear(r)
}