mirror of https://github.com/caddyserver/caddy.git
reverseproxy: Minor lint fixes
This commit is contained in:
parent
deedf8abb0
commit
132525de3b
|
@ -401,7 +401,7 @@ func (s CookieHashSelection) Select(pool UpstreamPool, req *http.Request, w http
|
||||||
// If there's no cookie, select new random host
|
// If there's no cookie, select new random host
|
||||||
if err != nil || cookie == nil {
|
if err != nil || cookie == nil {
|
||||||
return selectNewHostWithCookieHashSelection(pool, w, s.Secret, s.Name)
|
return selectNewHostWithCookieHashSelection(pool, w, s.Secret, s.Name)
|
||||||
} else {
|
}
|
||||||
// If the cookie is present, loop over the available upstreams until we find a match
|
// If the cookie is present, loop over the available upstreams until we find a match
|
||||||
cookieValue := cookie.Value
|
cookieValue := cookie.Value
|
||||||
for _, upstream := range pool {
|
for _, upstream := range pool {
|
||||||
|
@ -413,7 +413,6 @@ func (s CookieHashSelection) Select(pool UpstreamPool, req *http.Request, w http
|
||||||
return upstream
|
return upstream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// If there is no matching host, select new random host
|
// If there is no matching host, select new random host
|
||||||
return selectNewHostWithCookieHashSelection(pool, w, s.Secret, s.Name)
|
return selectNewHostWithCookieHashSelection(pool, w, s.Secret, s.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,11 +335,11 @@ func TestCookieHashPolicy(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
cookieHashPolicy := new(CookieHashSelection)
|
cookieHashPolicy := new(CookieHashSelection)
|
||||||
h := cookieHashPolicy.Select(pool, request, w)
|
h := cookieHashPolicy.Select(pool, request, w)
|
||||||
cookie_server1 := w.Result().Cookies()[0]
|
cookieServer1 := w.Result().Cookies()[0]
|
||||||
if cookie_server1 == nil {
|
if cookieServer1 == nil {
|
||||||
t.Error("cookieHashPolicy should set a cookie")
|
t.Error("cookieHashPolicy should set a cookie")
|
||||||
}
|
}
|
||||||
if cookie_server1.Name != "lb" {
|
if cookieServer1.Name != "lb" {
|
||||||
t.Error("cookieHashPolicy should set a cookie with name lb")
|
t.Error("cookieHashPolicy should set a cookie with name lb")
|
||||||
}
|
}
|
||||||
if h != pool[0] {
|
if h != pool[0] {
|
||||||
|
@ -349,7 +349,7 @@ func TestCookieHashPolicy(t *testing.T) {
|
||||||
pool[2].SetHealthy(true)
|
pool[2].SetHealthy(true)
|
||||||
request = httptest.NewRequest(http.MethodGet, "/test", nil)
|
request = httptest.NewRequest(http.MethodGet, "/test", nil)
|
||||||
w = httptest.NewRecorder()
|
w = httptest.NewRecorder()
|
||||||
request.AddCookie(cookie_server1)
|
request.AddCookie(cookieServer1)
|
||||||
h = cookieHashPolicy.Select(pool, request, w)
|
h = cookieHashPolicy.Select(pool, request, w)
|
||||||
if h != pool[0] {
|
if h != pool[0] {
|
||||||
t.Error("Expected cookieHashPolicy host to stick to the first host (matching cookie).")
|
t.Error("Expected cookieHashPolicy host to stick to the first host (matching cookie).")
|
||||||
|
@ -361,7 +361,7 @@ func TestCookieHashPolicy(t *testing.T) {
|
||||||
pool[0].SetHealthy(false)
|
pool[0].SetHealthy(false)
|
||||||
request = httptest.NewRequest(http.MethodGet, "/test", nil)
|
request = httptest.NewRequest(http.MethodGet, "/test", nil)
|
||||||
w = httptest.NewRecorder()
|
w = httptest.NewRecorder()
|
||||||
request.AddCookie(cookie_server1)
|
request.AddCookie(cookieServer1)
|
||||||
h = cookieHashPolicy.Select(pool, request, w)
|
h = cookieHashPolicy.Select(pool, request, w)
|
||||||
if h == pool[0] {
|
if h == pool[0] {
|
||||||
t.Error("Expected cookieHashPolicy to select a new host.")
|
t.Error("Expected cookieHashPolicy to select a new host.")
|
||||||
|
|
Loading…
Reference in New Issue