@marcel91200 / caddy Mirror · read-only / commits / 132525de
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

reverseproxy: Minor lint fixes

Matthew Holt committed Dec 14, 2020 at 15:30 UTC 132525de3bfd6acb16f8628fa057cb03e102a177
2 files changed +15 -16
modules/caddyhttp/reverseproxy/selectionpolicies.go
+10 -11
@@ -401,17 +401,16 @@ func (s CookieHashSelection) Select(pool UpstreamPool, req *http.Request, w http
401 // If there's no cookie, select new random host
402 if err != nil || cookie == nil {
403 return selectNewHostWithCookieHashSelection(pool, w, s.Secret, s.Name)
404 - } else {
405 - // If the cookie is present, loop over the available upstreams until we find a match
406 - cookieValue := cookie.Value
407 - for _, upstream := range pool {
408 - if !upstream.Available() {
409 - continue
410 - }
411 - sha, err := hashCookie(s.Secret, upstream.Dial)
412 - if err == nil && sha == cookieValue {
413 - return upstream
414 - }
404 + }
405 + // If the cookie is present, loop over the available upstreams until we find a match
406 + cookieValue := cookie.Value
407 + for _, upstream := range pool {
408 + if !upstream.Available() {
409 + continue
410 + }
411 + sha, err := hashCookie(s.Secret, upstream.Dial)
412 + if err == nil && sha == cookieValue {
413 + return upstream
414 }
415 }
416 // If there is no matching host, select new random host
modules/caddyhttp/reverseproxy/selectionpolicies_test.go
+5 -5
@@ -335,11 +335,11 @@ func TestCookieHashPolicy(t *testing.T) {
335 w := httptest.NewRecorder()
336 cookieHashPolicy := new(CookieHashSelection)
337 h := cookieHashPolicy.Select(pool, request, w)
338 - cookie_server1 := w.Result().Cookies()[0]
339 - if cookie_server1 == nil {
338 + cookieServer1 := w.Result().Cookies()[0]
339 + if cookieServer1 == nil {
340 t.Error("cookieHashPolicy should set a cookie")
341 }
342 - if cookie_server1.Name != "lb" {
342 + if cookieServer1.Name != "lb" {
343 t.Error("cookieHashPolicy should set a cookie with name lb")
344 }
345 if h != pool[0] {
@@ -349,7 +349,7 @@ func TestCookieHashPolicy(t *testing.T) {
349 pool[2].SetHealthy(true)
350 request = httptest.NewRequest(http.MethodGet, "/test", nil)
351 w = httptest.NewRecorder()
352 - request.AddCookie(cookie_server1)
352 + request.AddCookie(cookieServer1)
353 h = cookieHashPolicy.Select(pool, request, w)
354 if h != pool[0] {
355 t.Error("Expected cookieHashPolicy host to stick to the first host (matching cookie).")
@@ -361,7 +361,7 @@ func TestCookieHashPolicy(t *testing.T) {
361 pool[0].SetHealthy(false)
362 request = httptest.NewRequest(http.MethodGet, "/test", nil)
363 w = httptest.NewRecorder()
364 - request.AddCookie(cookie_server1)
364 + request.AddCookie(cookieServer1)
365 h = cookieHashPolicy.Select(pool, request, w)
366 if h == pool[0] {
367 t.Error("Expected cookieHashPolicy to select a new host.")