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
nexedi
caddy
Commits
ca3d23bc
Commit
ca3d23bc
authored
Jul 21, 2016
by
Tw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy: fix hyphen issue when parsing target
fix issue #948 Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
beae16f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
caddyhttp/proxy/setup_test.go
caddyhttp/proxy/setup_test.go
+20
-0
caddyhttp/proxy/upstream.go
caddyhttp/proxy/upstream.go
+10
-5
No files found.
caddyhttp/proxy/setup_test.go
View file @
ca3d23bc
...
...
@@ -111,6 +111,26 @@ func TestSetup(t *testing.T) {
"http://localhost:8085"
:
{},
},
},
// test #10 test hyphen without port range
{
"proxy / http://localhost:8001/a--b"
,
false
,
map
[
string
]
struct
{}{
"http://localhost:8001/a--b"
:
{},
},
},
// test #11 test hyphen with port range
{
"proxy / http://localhost:8001-8005/a--b"
,
false
,
map
[
string
]
struct
{}{
"http://localhost:8001/a--b"
:
{},
"http://localhost:8002/a--b"
:
{},
"http://localhost:8003/a--b"
:
{},
"http://localhost:8004/a--b"
:
{},
"http://localhost:8005/a--b"
:
{},
},
},
}
{
c
:=
caddy
.
NewTestController
(
"http"
,
test
.
input
)
err
:=
setup
(
c
)
...
...
caddyhttp/proxy/upstream.go
View file @
ca3d23bc
...
...
@@ -171,10 +171,15 @@ func parseUpstream(u string) ([]string, error) {
if
colonIdx
!=
-
1
&&
colonIdx
!=
protoIdx
{
us
:=
u
[
:
colonIdx
]
ports
:=
u
[
len
(
us
)
+
1
:
]
if
separators
:=
strings
.
Count
(
ports
,
"-"
);
separators
>
1
{
return
nil
,
fmt
.
Errorf
(
"port range [%s] is invalid"
,
ports
)
}
else
if
separators
==
1
{
ue
:=
""
portsEnd
:=
len
(
u
)
if
nextSlash
:=
strings
.
Index
(
u
[
colonIdx
:
],
"/"
);
nextSlash
!=
-
1
{
portsEnd
=
colonIdx
+
nextSlash
ue
=
u
[
portsEnd
:
]
}
ports
:=
u
[
len
(
us
)
+
1
:
portsEnd
]
if
separators
:=
strings
.
Count
(
ports
,
"-"
);
separators
==
1
{
portsStr
:=
strings
.
Split
(
ports
,
"-"
)
pIni
,
err
:=
strconv
.
Atoi
(
portsStr
[
0
])
if
err
!=
nil
{
...
...
@@ -192,7 +197,7 @@ func parseUpstream(u string) ([]string, error) {
hosts
:=
[]
string
{}
for
p
:=
pIni
;
p
<=
pEnd
;
p
++
{
hosts
=
append
(
hosts
,
fmt
.
Sprintf
(
"%s:%d
"
,
us
,
p
))
hosts
=
append
(
hosts
,
fmt
.
Sprintf
(
"%s:%d
%s"
,
us
,
p
,
ue
))
}
return
hosts
,
nil
}
...
...
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