mirror of
https://github.com/umputun/reproxy.git
synced 2025-02-16 18:34:30 +02:00
add Servers list and fill FQDNs
This commit is contained in:
parent
4e28e69997
commit
dfa0d51b31
@ -94,6 +94,19 @@ func (s *Service) Match(srv, src string) (string, bool) {
|
||||
return src, false
|
||||
}
|
||||
|
||||
// Servers return list of all servers, skips "*" (catch-all/default)
|
||||
func (s *Service) Servers() (servers []string) {
|
||||
s.lock.RLock()
|
||||
defer s.lock.RUnlock()
|
||||
for _, m := range s.mappers {
|
||||
if m.Server == "*" || m.Server == "" {
|
||||
continue
|
||||
}
|
||||
servers = append(servers, m.Server)
|
||||
}
|
||||
return servers
|
||||
}
|
||||
|
||||
func (s *Service) mergeLists() (res []UrlMapper) {
|
||||
for _, p := range s.providers {
|
||||
lst, err := p.List()
|
||||
|
@ -127,3 +127,48 @@ func TestService_Match(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_Servers(t *testing.T) {
|
||||
p1 := &ProviderMock{
|
||||
EventsFunc: func(ctx context.Context) <-chan struct{} {
|
||||
res := make(chan struct{}, 1)
|
||||
res <- struct{}{}
|
||||
return res
|
||||
},
|
||||
ListFunc: func() ([]UrlMapper, error) {
|
||||
return []UrlMapper{
|
||||
{SrcMatch: regexp.MustCompile("^/api/svc1/(.*)"), Dst: "http://127.0.0.1:8080/blah1/$1"},
|
||||
{Server: "m.example.com", SrcMatch: regexp.MustCompile("^/api/svc2/(.*)"),
|
||||
Dst: "http://127.0.0.2:8080/blah2/$1/abc"},
|
||||
}, nil
|
||||
},
|
||||
IDFunc: func() ProviderID {
|
||||
return PIFile
|
||||
},
|
||||
}
|
||||
p2 := &ProviderMock{
|
||||
EventsFunc: func(ctx context.Context) <-chan struct{} {
|
||||
return make(chan struct{}, 1)
|
||||
},
|
||||
ListFunc: func() ([]UrlMapper, error) {
|
||||
return []UrlMapper{
|
||||
{Server: "xx.reproxy.io", SrcMatch: regexp.MustCompile("/api/svc3/xyz"), Dst: "http://127.0.0.3:8080/blah3/xyz"},
|
||||
}, nil
|
||||
},
|
||||
IDFunc: func() ProviderID {
|
||||
return PIDocker
|
||||
},
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||
defer cancel()
|
||||
svc := NewService([]Provider{p1, p2})
|
||||
err := svc.Run(ctx)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, context.DeadlineExceeded, err)
|
||||
assert.Equal(t, 3, len(svc.mappers))
|
||||
|
||||
servers := svc.Servers()
|
||||
assert.Equal(t, []string{"m.example.com", "xx.reproxy.io"}, servers)
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ type Http struct {
|
||||
// If no match found return ok=false
|
||||
type Matcher interface {
|
||||
Match(srv, src string) (string, bool)
|
||||
Servers() (servers []string)
|
||||
}
|
||||
|
||||
// Run the lister and request's router, activate rest server
|
||||
@ -72,6 +73,7 @@ func (h *Http) Run(ctx context.Context) error {
|
||||
h.gzipHandler(),
|
||||
)
|
||||
|
||||
h.SSLConfig.FQDNs = h.Servers() // fill all servers
|
||||
switch h.SSLConfig.SSLMode {
|
||||
case SSLNone:
|
||||
log.Printf("[INFO] activate http proxy server on %s", h.Address)
|
||||
|
Loading…
x
Reference in New Issue
Block a user