From 23f2a04ed72610e677a516706e62800f557578b5 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Fri, 20 Nov 2020 11:09:02 -0600 Subject: [PATCH] TUN-3562: Fix panic when using bastion mode ingress rule --- ingress/origin_service.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ingress/origin_service.go b/ingress/origin_service.go index 7b810346..e8525672 100644 --- a/ingress/origin_service.go +++ b/ingress/origin_service.go @@ -84,10 +84,6 @@ func (o *localService) Dial(reqURL *url.URL, headers http.Header) (*gws.Conn, *h return d.Dial(reqURL.String(), headers) } -func (o *localService) address() string { - return o.URL.String() -} - func (o *localService) start(wg *sync.WaitGroup, log logger.Service, shutdownC <-chan struct{}, errC chan error, cfg OriginRequestConfig) error { transport, err := newHTTPTransport(o, cfg, log) if err != nil { @@ -151,7 +147,14 @@ func (o *localService) startProxy(staticHost string, wg *sync.WaitGroup, log log } func (o *localService) String() string { - return o.address() + if o.isBastion() { + return "Bastion" + } + return o.URL.String() +} + +func (o *localService) isBastion() bool { + return o.URL == nil } func (o *localService) RoundTrip(req *http.Request) (*http.Response, error) { @@ -163,6 +166,10 @@ func (o *localService) RoundTrip(req *http.Request) (*http.Response, error) { func (o *localService) staticHost() string { + if o.URL == nil { + return "" + } + addPortIfMissing := func(uri *url.URL, port int) string { if uri.Port() != "" { return uri.Host