Skip to content

Commit

Permalink
SRV: fix Caddyfile name inline arg, remove proto condition
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Jan 25, 2022
1 parent db5dee5 commit 65163e5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
Expand Up @@ -17,13 +17,13 @@

:8885 {
reverse_proxy {
dynamic srv _api._http.example.com
dynamic srv _api._tcp.example.com
}

reverse_proxy {
dynamic srv {
service api
proto http
proto tcp
name example.com
refresh 5m
resolvers 8.8.8.8 8.8.4.4
Expand Down Expand Up @@ -83,9 +83,7 @@
"handle": [
{
"dynamic_upstreams": {
"name": "example.com",
"proto": "http",
"service": "api",
"name": "_api._tcp.example.com",
"source": "srv"
},
"handler": "reverse_proxy"
Expand All @@ -95,7 +93,7 @@
"dial_fallback_delay": -1000000000,
"dial_timeout": 1000000000,
"name": "example.com",
"proto": "http",
"proto": "tcp",
"refresh": 300000000000,
"resolver": {
"addresses": [
Expand Down
10 changes: 2 additions & 8 deletions modules/caddyhttp/reverseproxy/caddyfile.go
Expand Up @@ -1056,7 +1056,7 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {

// UnmarshalCaddyfile deserializes Caddyfile tokens into h.
//
// dynamic srv [<address>] {
// dynamic srv [<name>] {
// service <service>
// proto <proto>
// name <name>
Expand All @@ -1073,13 +1073,7 @@ func (u *SRVUpstreams) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return d.ArgErr()
}
if len(args) > 0 {
service, proto, name, err := u.ParseAddress(args[0])
if err != nil {
return err
}
u.Service = service
u.Proto = proto
u.Name = name
u.Name = args[0]
}

for d.NextBlock(0) {
Expand Down
17 changes: 0 additions & 17 deletions modules/caddyhttp/reverseproxy/upstreams.go
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"net/http"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -80,9 +79,6 @@ func (su SRVUpstreams) String() string {

func (su *SRVUpstreams) Provision(ctx caddy.Context) error {
su.logger = ctx.Logger(su)
if su.Proto != "tcp" && su.Proto != "udp" {
return fmt.Errorf("invalid proto '%s'", su.Proto)
}
if su.Refresh == 0 {
su.Refresh = caddy.Duration(time.Minute)
}
Expand Down Expand Up @@ -176,19 +172,6 @@ func (su SRVUpstreams) GetUpstreams(r *http.Request) ([]*Upstream, error) {
return upstreams, nil
}

// ParseAddress takes a full SRV address and parses it into
// its three constituent parts. Used for parsing configuration
// so that users may specify the address with dots instead of
// specifying each part separately.
func (SRVUpstreams) ParseAddress(address string) (string, string, string, error) {
parts := strings.SplitN(address, ".", 3)
if len(parts) != 3 {
return "", "", "", fmt.Errorf("expected 3 parts (service, proto, name), got %d parts", len(parts))
}

return strings.TrimLeft(parts[0], "_"), strings.TrimLeft(parts[1], "_"), strings.TrimLeft(parts[2], "_"), nil
}

type srvLookup struct {
srvUpstreams SRVUpstreams
freshness time.Time
Expand Down

0 comments on commit 65163e5

Please sign in to comment.