Skip to content

Commit

Permalink
Fix --forward-connect-to not forwarding events (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcheung-stripe authored Feb 16, 2022
1 parent f8164a5 commit caa092d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
36 changes: 20 additions & 16 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,22 +493,26 @@ func Init(ctx context.Context, cfg *Config) (*Proxy, error) {
if err != nil {
return nil, err
}
} else if len(cfg.ForwardURL) > 0 {
// non-connect endpoints
endpointRoutes = append(endpointRoutes, EndpointRoute{
URL: parseURL(cfg.ForwardURL),
ForwardHeaders: cfg.ForwardHeaders,
Connect: false,
EventTypes: cfg.Events,
})

// connect endpoints
endpointRoutes = append(endpointRoutes, EndpointRoute{
URL: parseURL(cfg.ForwardConnectURL),
ForwardHeaders: cfg.ForwardConnectHeaders,
Connect: true,
EventTypes: cfg.Events,
})
} else {
if len(cfg.ForwardURL) > 0 {
// non-connect endpoints
endpointRoutes = append(endpointRoutes, EndpointRoute{
URL: parseURL(cfg.ForwardURL),
ForwardHeaders: cfg.ForwardHeaders,
Connect: false,
EventTypes: cfg.Events,
})
}

if len(cfg.ForwardConnectURL) > 0 {
// connect endpoints
endpointRoutes = append(endpointRoutes, EndpointRoute{
URL: parseURL(cfg.ForwardConnectURL),
ForwardHeaders: cfg.ForwardConnectHeaders,
Connect: true,
EventTypes: cfg.Events,
})
}
}

p := &Proxy{
Expand Down
40 changes: 40 additions & 0 deletions pkg/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,43 @@ func TestParseUrl(t *testing.T) {

require.Equal(t, "http://localhost:3000", parseURL("3000"))
}

func TestForwardToOnly(t *testing.T) {
cfg := Config{
ForwardURL: "http://localhost:4242",
ForwardConnectURL: "",
}
p, err := Init(context.Background(), &cfg)
require.NoError(t, err)
require.Equal(t, 2, len(p.endpointClients))
require.EqualValues(t, "http://localhost:4242", p.endpointClients[0].URL)
require.EqualValues(t, false, p.endpointClients[0].connect)
require.EqualValues(t, "http://localhost:4242", p.endpointClients[1].URL)
require.EqualValues(t, true, p.endpointClients[1].connect)
}

func TestForwardConnectToOnly(t *testing.T) {
cfg := Config{
ForwardURL: "",
ForwardConnectURL: "http://localhost:4242/connect",
}
p, err := Init(context.Background(), &cfg)
require.NoError(t, err)
require.Equal(t, 1, len(p.endpointClients))
require.EqualValues(t, "http://localhost:4242/connect", p.endpointClients[0].URL)
require.EqualValues(t, true, p.endpointClients[0].connect)
}

func TestForwardToAndForwardConnectTo(t *testing.T) {
cfg := Config{
ForwardURL: "http://localhost:4242",
ForwardConnectURL: "http://localhost:4242/connect",
}
p, err := Init(context.Background(), &cfg)
require.NoError(t, err)
require.Equal(t, 2, len(p.endpointClients))
require.EqualValues(t, "http://localhost:4242", p.endpointClients[0].URL)
require.EqualValues(t, false, p.endpointClients[0].connect)
require.EqualValues(t, "http://localhost:4242/connect", p.endpointClients[1].URL)
require.EqualValues(t, true, p.endpointClients[1].connect)
}

0 comments on commit caa092d

Please sign in to comment.