Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
caddy
Commits
be1c57ac
Commit
be1c57ac
authored
Sep 27, 2016
by
Kris Hamoud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1136 fix
logic change
parent
4adbcd25
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
15 deletions
+10
-15
caddyhttp/proxy/policy.go
caddyhttp/proxy/policy.go
+4
-9
caddyhttp/proxy/policy_test.go
caddyhttp/proxy/policy_test.go
+6
-6
No files found.
caddyhttp/proxy/policy.go
View file @
be1c57ac
...
@@ -121,18 +121,13 @@ func (r *IPHash) Select(pool HostPool, request *http.Request) *UpstreamHost {
...
@@ -121,18 +121,13 @@ func (r *IPHash) Select(pool HostPool, request *http.Request) *UpstreamHost {
if
err
!=
nil
{
if
err
!=
nil
{
clientIP
=
request
.
RemoteAddr
clientIP
=
request
.
RemoteAddr
}
}
hash
:=
hash
(
clientIP
)
index
:=
hash
(
clientIP
)
%
poolLen
for
{
for
i
:=
uint32
(
0
);
i
<
poolLen
;
i
++
{
if
poolLen
==
0
{
index
+=
i
break
host
:=
pool
[
index
%
poolLen
]
}
index
:=
hash
%
poolLen
host
:=
pool
[
index
]
if
host
.
Available
()
{
if
host
.
Available
()
{
return
host
return
host
}
}
pool
=
append
(
pool
[
:
index
],
pool
[
index
+
1
:
]
...
)
poolLen
--
}
}
return
nil
return
nil
}
}
caddyhttp/proxy/policy_test.go
View file @
be1c57ac
...
@@ -163,14 +163,14 @@ func TestIPHashPolicy(t *testing.T) {
...
@@ -163,14 +163,14 @@ func TestIPHashPolicy(t *testing.T) {
request
.
RemoteAddr
=
"172.0.0.1"
request
.
RemoteAddr
=
"172.0.0.1"
pool
[
1
]
.
Unhealthy
=
true
pool
[
1
]
.
Unhealthy
=
true
h
=
ipHash
.
Select
(
pool
,
request
)
h
=
ipHash
.
Select
(
pool
,
request
)
if
h
!=
pool
[
0
]
{
if
h
!=
pool
[
2
]
{
t
.
Error
(
"Expected ip hash policy host to be the
first
host."
)
t
.
Error
(
"Expected ip hash policy host to be the
third
host."
)
}
}
request
.
RemoteAddr
=
"172.0.0.2"
request
.
RemoteAddr
=
"172.0.0.2"
h
=
ipHash
.
Select
(
pool
,
request
)
h
=
ipHash
.
Select
(
pool
,
request
)
if
h
!=
pool
[
1
]
{
if
h
!=
pool
[
2
]
{
t
.
Error
(
"Expected ip hash policy host to be the
secon
d host."
)
t
.
Error
(
"Expected ip hash policy host to be the
thir
d host."
)
}
}
pool
[
1
]
.
Unhealthy
=
false
pool
[
1
]
.
Unhealthy
=
false
...
@@ -182,8 +182,8 @@ func TestIPHashPolicy(t *testing.T) {
...
@@ -182,8 +182,8 @@ func TestIPHashPolicy(t *testing.T) {
}
}
request
.
RemoteAddr
=
"172.0.0.4"
request
.
RemoteAddr
=
"172.0.0.4"
h
=
ipHash
.
Select
(
pool
,
request
)
h
=
ipHash
.
Select
(
pool
,
request
)
if
h
!=
pool
[
0
]
{
if
h
!=
pool
[
1
]
{
t
.
Error
(
"Expected ip hash policy host to be the
first
host."
)
t
.
Error
(
"Expected ip hash policy host to be the
second
host."
)
}
}
// We should be able to resize the host pool and still be able to predict
// We should be able to resize the host pool and still be able to predict
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment