Debian Codegraph @

modules/caddyhttp/reverseproxy/selectionpolicies_test.go

raw symbols SCIP
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package reverseproxyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/
16
17 import (
18 "contextscip-go gomod github.com/golang/go/src go1.25.1 context/"
19 "net/httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/"
20 "net/http/httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/"
21 "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/"
22
23 "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/"
24 "github.com/caddyserver/caddy/v2/caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/"
25 "github.com/caddyserver/caddy/v2/modules/caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/"
26 )
27
28 func testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().() UpstreamPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamPool# {
29 return UpstreamPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamPool#{
30 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#), Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: "0.0.0.1"},
31 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#), Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: "0.0.0.2"},
32 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#), Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: "0.0.0.3"},
33 }
34 }
35
36 func TestRoundRobinPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestRoundRobinPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
37 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
38 rrPolicy := RoundRobinSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RoundRobinSelection#{}
39 req, _ := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewRequest().("GET", "/", nil)
40
41 h := rrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RoundRobinSelection#Select().(pool, req, nil)
42 // First selected host is 1, because counter starts at 0
43 // and increments before host is selected
44 if h != pool[1] {
45 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected first round robin host to be second host in the pool.")
46 }
47 h = rrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RoundRobinSelection#Select().(pool, req, nil)
48 if h != pool[2] {
49 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected second round robin host to be third host in the pool.")
50 }
51 h = rrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RoundRobinSelection#Select().(pool, req, nil)
52 if h != pool[0] {
53 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected third round robin host to be first host in the pool.")
54 }
55 // mark host as down
56 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
57 h = rrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RoundRobinSelection#Select().(pool, req, nil)
58 if h != pool[2] {
59 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected to skip down host.")
60 }
61 // mark host as up
62 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
63
64 h = rrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RoundRobinSelection#Select().(pool, req, nil)
65 if h == pool[2] {
66 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected to balance evenly among healthy hosts")
67 }
68 // mark host as full
69 pool[1].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(1)
70 pool[1].MaxRequestsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#MaxRequests. = 1
71 h = rrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RoundRobinSelection#Select().(pool, req, nil)
72 if h != pool[2] {
73 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected to skip full host.")
74 }
75 }
76
77 func TestWeightedRoundRobinPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestWeightedRoundRobinPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
78 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
79 wrrPolicy := WeightedRoundRobinSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#{
80 Weightsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Weights.: []int{3, 2, 1},
81 totalWeightscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#totalWeight.: 6,
82 }
83 req, _ := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewRequest().("GET", "/", nil)
84
85 h := wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
86 if h != pool[0] {
87 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected first weighted round robin host to be first host in the pool.")
88 }
89 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
90 if h != pool[0] {
91 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected second weighted round robin host to be first host in the pool.")
92 }
93 // Third selected host is 1, because counter starts at 0
94 // and increments before host is selected
95 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
96 if h != pool[1] {
97 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected third weighted round robin host to be second host in the pool.")
98 }
99 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
100 if h != pool[1] {
101 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected fourth weighted round robin host to be second host in the pool.")
102 }
103 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
104 if h != pool[2] {
105 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected fifth weighted round robin host to be third host in the pool.")
106 }
107 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
108 if h != pool[0] {
109 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected sixth weighted round robin host to be first host in the pool.")
110 }
111
112 // mark host as down
113 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
114 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
115 if h != pool[1] {
116 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected to skip down host.")
117 }
118 // mark host as up
119 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
120
121 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
122 if h != pool[0] {
123 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected to select first host on availability.")
124 }
125 // mark host as full
126 pool[1].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(1)
127 pool[1].MaxRequestsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#MaxRequests. = 1
128 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
129 if h != pool[2] {
130 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected to skip full host.")
131 }
132 }
133
134 func TestWeightedRoundRobinPolicyWithZeroWeightscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestWeightedRoundRobinPolicyWithZeroWeight().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
135 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
136 wrrPolicy := WeightedRoundRobinSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#{
137 Weightsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Weights.: []int{0, 2, 1},
138 totalWeightscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#totalWeight.: 3,
139 }
140 req, _ := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewRequest().("GET", "/", nil)
141
142 h := wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
143 if h != pool[1] {
144 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected first weighted round robin host to be second host in the pool.")
145 }
146
147 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
148 if h != pool[2] {
149 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected second weighted round robin host to be third host in the pool.")
150 }
151
152 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
153 if h != pool[1] {
154 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected third weighted round robin host to be second host in the pool.")
155 }
156
157 // mark second host as down
158 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
159 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
160 if h != pool[2] {
161 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expect select next available host.")
162 }
163
164 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
165 if h != pool[2] {
166 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expect select only available host.")
167 }
168 // mark second host as up
169 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
170
171 h = wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
172 if h != pool[1] {
173 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expect select first host on availability.")
174 }
175
176 // test next select in full cycle
177 expected := []*Upstreamscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#{pool[1], pool[2], pool[1], pool[1], pool[2], pool[1]}
178 for i, want := range expected {
179 got := wrrPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/WeightedRoundRobinSelection#Select().(pool, req, nil)
180 if want != got {
181 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Selection %d: got host[%s], want host[%s]", i+1, got, want)
182 }
183 }
184 }
185
186 func TestLeastConnPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestLeastConnPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
187 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
188 lcPolicy := LeastConnSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/LeastConnSelection#{}
189 req, _ := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewRequest().("GET", "/", nil)
190
191 pool[0].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(10)
192 pool[1].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(10)
193 h := lcPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/LeastConnSelection#Select().(pool, req, nil)
194 if h != pool[2] {
195 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected least connection host to be third host.")
196 }
197 pool[2].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(100)
198 h = lcPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/LeastConnSelection#Select().(pool, req, nil)
199 if h != pool[0] && h != pool[1] {
200 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected least connection host to be first or second host.")
201 }
202 }
203
204 func TestIPHashPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestIPHashPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
205 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
206 ipHash := IPHashSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#{}
207 req, _ := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewRequest().("GET", "/", nil)
208
209 // We should be able to predict where every request is routed.
210 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.1:80"
211 h := ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
212 if h != pool[0] {
213 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
214 }
215 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.2:80"
216 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
217 if h != pool[1] {
218 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
219 }
220 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.3:80"
221 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
222 if h != pool[0] {
223 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
224 }
225 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.4:80"
226 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
227 if h != pool[1] {
228 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
229 }
230
231 // we should get the same results without a port
232 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.1"
233 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
234 if h != pool[0] {
235 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
236 }
237 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.2"
238 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
239 if h != pool[1] {
240 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
241 }
242 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.3"
243 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
244 if h != pool[0] {
245 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
246 }
247 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.4"
248 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
249 if h != pool[1] {
250 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
251 }
252
253 // we should get a healthy host if the original host is unhealthy and a
254 // healthy host is available
255 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.4"
256 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
257 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
258 if h != pool[2] {
259 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the third host.")
260 }
261
262 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.2"
263 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
264 if h != pool[0] {
265 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
266 }
267 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
268
269 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.3"
270 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
271 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
272 if h != pool[0] {
273 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
274 }
275 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.4"
276 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
277 if h != pool[1] {
278 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
279 }
280
281 // We should be able to resize the host pool and still be able to predict
282 // where a req will be routed with the same IP's used above
283 pool = UpstreamPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamPool#{
284 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#), Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: "0.0.0.2"},
285 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#), Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: "0.0.0.3"},
286 }
287 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.1:80"
288 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
289 if h != pool[0] {
290 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
291 }
292 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.2:80"
293 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
294 if h != pool[0] {
295 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
296 }
297 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.3:80"
298 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
299 if h != pool[0] {
300 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
301 }
302 req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "172.0.0.4:80"
303 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
304 if h != pool[0] {
305 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
306 }
307
308 // We should get nil when there are no healthy hosts
309 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
310 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
311 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
312 if h != nil {
313 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be nil.")
314 }
315
316 // Reproduce #4135
317 pool = UpstreamPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamPool#{
318 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
319 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
320 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
321 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
322 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
323 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
324 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
325 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
326 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
327 }
328 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
329 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
330 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
331 pool[3].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
332 pool[4].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
333 pool[5].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
334 pool[6].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
335 pool[7].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
336 pool[8].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
337
338 // We should get a result back when there is one healthy host left.
339 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/IPHashSelection#Select().(pool, req, nil)
340 if h == nil {
341 // If it is nil, it means we missed a host even though one is available
342 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to not be nil, but it is nil.")
343 }
344 }
345
346 func TestClientIPHashPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestClientIPHashPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
347 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
348 ipHash := ClientIPHashSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#{}
349 req, _ := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewRequest().("GET", "/", nil)
350 req = req.WithContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#WithContext().(contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.VarsCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/VarsCtxKey., make(map[string]any)))
351
352 // We should be able to predict where every request is routed.
353 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.1:80")
354 h := ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
355 if h != pool[0] {
356 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
357 }
358 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.2:80")
359 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
360 if h != pool[1] {
361 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
362 }
363 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.3:80")
364 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
365 if h != pool[0] {
366 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
367 }
368 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.4:80")
369 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
370 if h != pool[1] {
371 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
372 }
373
374 // we should get the same results without a port
375 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.1")
376 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
377 if h != pool[0] {
378 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
379 }
380 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.2")
381 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
382 if h != pool[1] {
383 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
384 }
385 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.3")
386 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
387 if h != pool[0] {
388 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
389 }
390 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.4")
391 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
392 if h != pool[1] {
393 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
394 }
395
396 // we should get a healthy host if the original host is unhealthy and a
397 // healthy host is available
398 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.4")
399 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
400 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
401 if h != pool[2] {
402 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the third host.")
403 }
404
405 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.2")
406 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
407 if h != pool[0] {
408 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
409 }
410 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
411
412 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.3")
413 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
414 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
415 if h != pool[0] {
416 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
417 }
418 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.4")
419 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
420 if h != pool[1] {
421 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the second host.")
422 }
423
424 // We should be able to resize the host pool and still be able to predict
425 // where a req will be routed with the same IP's used above
426 pool = UpstreamPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamPool#{
427 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#), Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: "0.0.0.2"},
428 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#), Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: "0.0.0.3"},
429 }
430 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.1:80")
431 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
432 if h != pool[0] {
433 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
434 }
435 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.2:80")
436 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
437 if h != pool[0] {
438 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
439 }
440 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.3:80")
441 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
442 if h != pool[0] {
443 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
444 }
445 caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey., "172.0.0.4:80")
446 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
447 if h != pool[0] {
448 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be the first host.")
449 }
450
451 // We should get nil when there are no healthy hosts
452 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
453 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
454 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
455 if h != nil {
456 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to be nil.")
457 }
458
459 // Reproduce #4135
460 pool = UpstreamPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamPool#{
461 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
462 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
463 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
464 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
465 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
466 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
467 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
468 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
469 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
470 }
471 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
472 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
473 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
474 pool[3].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
475 pool[4].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
476 pool[5].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
477 pool[6].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
478 pool[7].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
479 pool[8].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
480
481 // We should get a result back when there is one healthy host left.
482 h = ipHash.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ClientIPHashSelection#Select().(pool, req, nil)
483 if h == nil {
484 // If it is nil, it means we missed a host even though one is available
485 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected ip hash policy host to not be nil, but it is nil.")
486 }
487 }
488
489 func TestFirstPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestFirstPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
490 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
491 firstPolicy := FirstSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/FirstSelection#{}
492 req := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/", nil)
493
494 h := firstPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/FirstSelection#Select().(pool, req, nil)
495 if h != pool[0] {
496 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected first policy host to be the first host.")
497 }
498
499 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
500 h = firstPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/FirstSelection#Select().(pool, req, nil)
501 if h != pool[1] {
502 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected first policy host to be the second host.")
503 }
504 }
505
506 func TestQueryHashPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestQueryHashPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
507 ctx, cancel := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NewContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewContext().(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#{Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Context.: contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.1 context/Background().()})
508 defer cancel()
509 queryPolicy := QueryHashSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#{Keyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Key.: "foo"}
510 if err := queryPolicy.Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Provision().(ctx); err != nil {
511 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Provision error: %v", err)
512 t.FailNowscip-go gomod github.com/golang/go/src go1.25.1 testing/common#FailNow().()
513 }
514
515 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
516
517 request := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/?foo=1", nil)
518 h := queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
519 if h != pool[0] {
520 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be the first host.")
521 }
522
523 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/?foo=100000", nil)
524 h = queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
525 if h != pool[1] {
526 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be the second host.")
527 }
528
529 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/?foo=1", nil)
530 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
531 h = queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
532 if h != pool[2] {
533 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be the third host.")
534 }
535
536 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/?foo=100000", nil)
537 h = queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
538 if h != pool[1] {
539 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be the second host.")
540 }
541
542 // We should be able to resize the host pool and still be able to predict
543 // where a request will be routed with the same query used above
544 pool = UpstreamPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamPool#{
545 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
546 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
547 }
548
549 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/?foo=1", nil)
550 h = queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
551 if h != pool[0] {
552 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be the first host.")
553 }
554
555 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
556 h = queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
557 if h != pool[1] {
558 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be the second host.")
559 }
560
561 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/?foo=4", nil)
562 h = queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
563 if h != pool[1] {
564 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be the second host.")
565 }
566
567 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
568 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
569 h = queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
570 if h != nil {
571 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be nil.")
572 }
573
574 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/?foo=aa11&foo=bb22", nil)
575 pool = testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
576 h = queryPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/QueryHashSelection#Select().(pool, request, nil)
577 if h != pool[0] {
578 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected query policy host to be the first host.")
579 }
580 }
581
582 func TestURIHashPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestURIHashPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
583 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
584 uriPolicy := URIHashSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/URIHashSelection#{}
585
586 request := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
587 h := uriPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/URIHashSelection#Select().(pool, request, nil)
588 if h != pool[2] {
589 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected uri policy host to be the third host.")
590 }
591
592 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
593 h = uriPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/URIHashSelection#Select().(pool, request, nil)
594 if h != pool[0] {
595 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected uri policy host to be the first host.")
596 }
597
598 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test_2", nil)
599 h = uriPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/URIHashSelection#Select().(pool, request, nil)
600 if h != pool[0] {
601 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected uri policy host to be the first host.")
602 }
603
604 // We should be able to resize the host pool and still be able to predict
605 // where a request will be routed with the same URI's used above
606 pool = UpstreamPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamPool#{
607 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
608 {Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)},
609 }
610
611 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
612 h = uriPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/URIHashSelection#Select().(pool, request, nil)
613 if h != pool[0] {
614 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected uri policy host to be the first host.")
615 }
616
617 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
618 h = uriPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/URIHashSelection#Select().(pool, request, nil)
619 if h != pool[1] {
620 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected uri policy host to be the first host.")
621 }
622
623 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test_2", nil)
624 h = uriPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/URIHashSelection#Select().(pool, request, nil)
625 if h != pool[1] {
626 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected uri policy host to be the second host.")
627 }
628
629 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
630 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
631 h = uriPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/URIHashSelection#Select().(pool, request, nil)
632 if h != nil {
633 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected uri policy host to be nil.")
634 }
635 }
636
637 func TestLeastRequestsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestLeastRequests().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
638 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
639 pool[0].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8080"
640 pool[1].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8081"
641 pool[2].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8082"
642 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
643 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
644 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
645 pool[0].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(10)
646 pool[1].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(20)
647 pool[2].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(30)
648
649 result := leastRequestsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/leastRequests().(pool)
650
651 if result == nil {
652 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Least request should not return nil")
653 }
654
655 if result != pool[0] {
656 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Least request should return pool[0]")
657 }
658 }
659
660 func TestRandomChoicePolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestRandomChoicePolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
661 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
662 pool[0].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8080"
663 pool[1].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8081"
664 pool[2].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8082"
665 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
666 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
667 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
668 pool[0].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(10)
669 pool[1].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(20)
670 pool[2].countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(30)
671
672 request := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
673 randomChoicePolicy := RandomChoiceSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RandomChoiceSelection#{Choosescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RandomChoiceSelection#Choose.: 2}
674
675 h := randomChoicePolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/RandomChoiceSelection#Select().(pool, request, nil)
676
677 if h == nil {
678 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("RandomChoicePolicy should not return nil")
679 }
680
681 if h == pool[0] {
682 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("RandomChoicePolicy should not choose pool[0]")
683 }
684 }
685
686 func TestCookieHashPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestCookieHashPolicy().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
687 ctx, cancel := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NewContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewContext().(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#{Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Context.: contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.1 context/Background().()})
688 defer cancel()
689 cookieHashPolicy := CookieHashSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#{}
690 if err := cookieHashPolicy.Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Provision().(ctx); err != nil {
691 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Provision error: %v", err)
692 t.FailNowscip-go gomod github.com/golang/go/src go1.25.1 testing/common#FailNow().()
693 }
694
695 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
696 pool[0].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8080"
697 pool[1].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8081"
698 pool[2].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8082"
699 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
700 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
701 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
702 request := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
703 w := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().()
704
705 h := cookieHashPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Select().(pool, request, w)
706 cookieServer1 := w.Resultscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Result().().Cookiesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Cookies().()[0]
707 if cookieServer1 == nil {
708 t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().("cookieHashPolicy should set a cookie")
709 }
710 if cookieServer1.Namescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Cookie#Name. != "lb" {
711 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("cookieHashPolicy should set a cookie with name lb")
712 }
713 if cookieServer1.Securescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Cookie#Secure. {
714 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("cookieHashPolicy should set cookie Secure attribute to false when request is not secure")
715 }
716 if h != pool[0] {
717 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookieHashPolicy host to be the first only available host.")
718 }
719 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
720 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
721 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
722 w = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().()
723 request.AddCookiescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#AddCookie().(cookieServer1)
724 h = cookieHashPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Select().(pool, request, w)
725 if h != pool[0] {
726 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookieHashPolicy host to stick to the first host (matching cookie).")
727 }
728 s := w.Resultscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Result().().Cookiesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Cookies().()
729 if len(s) != 0 {
730 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookieHashPolicy to not set a new cookie.")
731 }
732 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
733 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
734 w = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().()
735 request.AddCookiescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#AddCookie().(cookieServer1)
736 h = cookieHashPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Select().(pool, request, w)
737 if h == pool[0] {
738 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookieHashPolicy to select a new host.")
739 }
740 if w.Resultscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Result().().Cookiesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Cookies().() == nil {
741 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookieHashPolicy to set a new cookie.")
742 }
743 }
744
745 func TestCookieHashPolicyWithSecureRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestCookieHashPolicyWithSecureRequest().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
746 ctx, cancel := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NewContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewContext().(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#{Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Context.: contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.1 context/Background().()})
747 defer cancel()
748 cookieHashPolicy := CookieHashSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#{}
749 if err := cookieHashPolicy.Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Provision().(ctx); err != nil {
750 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Provision error: %v", err)
751 t.FailNowscip-go gomod github.com/golang/go/src go1.25.1 testing/common#FailNow().()
752 }
753
754 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
755 pool[0].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8080"
756 pool[1].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8081"
757 pool[2].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8082"
758 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
759 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
760 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
761
762 // Create a test server that serves HTTPS requests
763 ts := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewTLSServerscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewTLSServer().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) {
764 h := cookieHashPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Select().(pool, r, w)
765 if h != pool[0] {
766 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookieHashPolicy host to be the first only available host.")
767 }
768 }))
769 defer ts.Closescip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/Server#Close().()
770
771 // Make a new HTTPS request to the test server
772 client := ts.Clientscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/Server#Client().()
773 request, err := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., ts.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/Server#URL.+"/test", nil)
774 if err != nil {
775 t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().(err)
776 }
777 response, err := client.Doscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Client#Do().(request)
778 if err != nil {
779 t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().(err)
780 }
781
782 // Check if the cookie set is Secure and has SameSiteNone mode
783 cookies := response.Cookiesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Cookies().()
784 if len(cookies) == 0 {
785 t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().("Expected a cookie to be set")
786 }
787 cookie := cookies[0]
788 if !cookie.Securescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Cookie#Secure. {
789 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookie Secure attribute to be true when request is secure")
790 }
791 if cookie.SameSitescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Cookie#SameSite. != httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.SameSiteNoneModescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/SameSiteNoneMode. {
792 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookie SameSite attribute to be None when request is secure")
793 }
794 }
795
796 func TestCookieHashPolicyWithFirstFallbackscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestCookieHashPolicyWithFirstFallback().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
797 ctx, cancel := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NewContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewContext().(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#{Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Context.: contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.1 context/Background().()})
798 defer cancel()
799 cookieHashPolicy := CookieHashSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#{
800 FallbackRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#FallbackRaw.: caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONModuleObjectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSONModuleObject().(FirstSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/FirstSelection#{}, "policy", "first", nil),
801 }
802 if err := cookieHashPolicy.Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Provision().(ctx); err != nil {
803 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Provision error: %v", err)
804 t.FailNowscip-go gomod github.com/golang/go/src go1.25.1 testing/common#FailNow().()
805 }
806
807 pool := testPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/testPool().()
808 pool[0].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8080"
809 pool[1].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8081"
810 pool[2].Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial. = "localhost:8082"
811 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
812 pool[1].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
813 pool[2].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(true)
814 request := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
815 w := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().()
816
817 h := cookieHashPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Select().(pool, request, w)
818 cookieServer1 := w.Resultscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Result().().Cookiesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Cookies().()[0]
819 if cookieServer1 == nil {
820 t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().("cookieHashPolicy should set a cookie")
821 }
822 if cookieServer1.Namescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Cookie#Name. != "lb" {
823 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("cookieHashPolicy should set a cookie with name lb")
824 }
825 if h != pool[0] {
826 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Expected cookieHashPolicy host to be the first only available host, got %s", h)
827 }
828 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
829 w = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().()
830 request.AddCookiescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#AddCookie().(cookieServer1)
831 h = cookieHashPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Select().(pool, request, w)
832 if h != pool[0] {
833 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Expected cookieHashPolicy host to stick to the first host (matching cookie), got %s", h)
834 }
835 s := w.Resultscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Result().().Cookiesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Cookies().()
836 if len(s) != 0 {
837 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookieHashPolicy to not set a new cookie.")
838 }
839 pool[0].setHealthyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#setHealthy().(false)
840 request = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/test", nil)
841 w = httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().()
842 request.AddCookiescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#AddCookie().(cookieServer1)
843 h = cookieHashPolicy.Selectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/CookieHashSelection#Select().(pool, request, w)
844 if h != pool[1] {
845 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Expected cookieHashPolicy to select the next first available host, got %s", h)
846 }
847 if w.Resultscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Result().().Cookiesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Cookies().() == nil {
848 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("Expected cookieHashPolicy to set a new cookie.")
849 }
850 }