mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-26 21:53:48 +03:00
reverseproxy: Add support for specifying IDs in Caddyfile
This commit is contained in:
parent
a5f4fae145
commit
5968ebd0f4
2 changed files with 54 additions and 2 deletions
46
caddytest/integration/caddyfile_adapt/reverse_proxy_ids.txt
Normal file
46
caddytest/integration/caddyfile_adapt/reverse_proxy_ids.txt
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
:8884
|
||||||
|
|
||||||
|
reverse_proxy one|http://localhost two|http://localhost {
|
||||||
|
to three|srv+http://localhost four|srv+http://localhost
|
||||||
|
}
|
||||||
|
----------
|
||||||
|
{
|
||||||
|
"apps": {
|
||||||
|
"http": {
|
||||||
|
"servers": {
|
||||||
|
"srv0": {
|
||||||
|
"listen": [
|
||||||
|
":8884"
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"handle": [
|
||||||
|
{
|
||||||
|
"handler": "reverse_proxy",
|
||||||
|
"upstreams": [
|
||||||
|
{
|
||||||
|
"dial": "localhost:80",
|
||||||
|
"id": "one"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dial": "localhost:80",
|
||||||
|
"id": "two"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "three",
|
||||||
|
"lookup_srv": "localhost"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "four",
|
||||||
|
"lookup_srv": "localhost"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -219,6 +219,12 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
// treated as a SRV-based upstream, and any port will be
|
// treated as a SRV-based upstream, and any port will be
|
||||||
// dropped.
|
// dropped.
|
||||||
appendUpstream := func(address string) error {
|
appendUpstream := func(address string) error {
|
||||||
|
var id string
|
||||||
|
if strings.Contains(address, "|") {
|
||||||
|
parts := strings.SplitN(address, "|", 2)
|
||||||
|
id = parts[0]
|
||||||
|
address = parts[1]
|
||||||
|
}
|
||||||
isSRV := strings.HasPrefix(address, "srv+")
|
isSRV := strings.HasPrefix(address, "srv+")
|
||||||
if isSRV {
|
if isSRV {
|
||||||
address = strings.TrimPrefix(address, "srv+")
|
address = strings.TrimPrefix(address, "srv+")
|
||||||
|
@ -231,9 +237,9 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
if host, _, err := net.SplitHostPort(dialAddr); err == nil {
|
if host, _, err := net.SplitHostPort(dialAddr); err == nil {
|
||||||
dialAddr = host
|
dialAddr = host
|
||||||
}
|
}
|
||||||
h.Upstreams = append(h.Upstreams, &Upstream{LookupSRV: dialAddr})
|
h.Upstreams = append(h.Upstreams, &Upstream{ID: id, LookupSRV: dialAddr})
|
||||||
} else {
|
} else {
|
||||||
h.Upstreams = append(h.Upstreams, &Upstream{Dial: dialAddr})
|
h.Upstreams = append(h.Upstreams, &Upstream{ID: id, Dial: dialAddr})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue