Skip to content

Commit

Permalink
register module
Browse files Browse the repository at this point in the history
  • Loading branch information
utick authored and d-masson committed Nov 4, 2020
1 parent 7f0a189 commit 0cc999d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/caddyhttp/reverseproxy/selectionpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func init() {
caddy.RegisterModule(IPHashSelection{})
caddy.RegisterModule(URIHashSelection{})
caddy.RegisterModule(HeaderHashSelection{})
caddy.RegisterModule(CookieHashSelection{})

weakrand.Seed(time.Now().UTC().UnixNano())
}
Expand Down Expand Up @@ -409,13 +410,12 @@ func (s CookieHashSelection) Select(pool UpstreamPool, req *http.Request, w http
}
cookie, err := req.Cookie(s.Field)
var cookieValue string
if err != nil {
if err != nil || cookie == nil {
cookieValue = caddy.RandomString(16)
http.SetCookie(w, &http.Cookie{Name: "order", Value: cookieValue, Secure: false})
http.SetCookie(w, &http.Cookie{Name: s.Field, Value: cookieValue, Secure: false})
} else {
cookieValue = cookie.Value
}
cookieValue = cookie.Value
return hostByHashing(pool, cookieValue)
}

Expand Down Expand Up @@ -492,6 +492,7 @@ var (
_ Selector = (*IPHashSelection)(nil)
_ Selector = (*URIHashSelection)(nil)
_ Selector = (*HeaderHashSelection)(nil)
_ Selector = (*CookieHashSelection)(nil)

_ caddy.Validator = (*RandomChoiceSelection)(nil)
_ caddy.Provisioner = (*RandomChoiceSelection)(nil)
Expand Down

0 comments on commit 0cc999d

Please sign in to comment.