Don't parse cookies twice
This commit is contained in:
parent
30b57ded50
commit
f33a44bb1f
|
@ -28,13 +28,12 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseRequest(w http.ResponseWriter, r *http.Request) (*request, *statRequest) {
|
func parseRequest(w http.ResponseWriter, r *http.Request) (*request, *statRequest) {
|
||||||
setCookie(w, r)
|
sid := sessionID(w, r)
|
||||||
cook, _ := r.Cookie(cookieName)
|
login, _ := redis.String(redisPool.Get().Do("HGET", "sessions", sid))
|
||||||
login, _ := redis.String(redisPool.Get().Do("HGET", "sessions", cook.Value))
|
|
||||||
req := &request{
|
req := &request{
|
||||||
r: r,
|
r: r,
|
||||||
w: w,
|
w: w,
|
||||||
sessionID: cook.Value,
|
sessionID: sid,
|
||||||
login: login,
|
login: login,
|
||||||
}
|
}
|
||||||
return req, parseStatRequest(r)
|
return req, parseStatRequest(r)
|
||||||
|
@ -77,8 +76,10 @@ func parseStatRequest(r *http.Request) *statRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCookie(w http.ResponseWriter, r *http.Request) {
|
func sessionID(w http.ResponseWriter, r *http.Request) string {
|
||||||
if cook, err := r.Cookie(cookieName); err != nil {
|
var cook *http.Cookie
|
||||||
|
var err error
|
||||||
|
if cook, err = r.Cookie(cookieName); err != nil {
|
||||||
cook = &http.Cookie{
|
cook = &http.Cookie{
|
||||||
Name: cookieName,
|
Name: cookieName,
|
||||||
Value: uuid.New(),
|
Value: uuid.New(),
|
||||||
|
@ -89,4 +90,5 @@ func setCookie(w http.ResponseWriter, r *http.Request) {
|
||||||
http.SetCookie(w, cook)
|
http.SetCookie(w, cook)
|
||||||
r.AddCookie(cook)
|
r.AddCookie(cook)
|
||||||
}
|
}
|
||||||
|
return cook.Value
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue