Split port from hostname in full urls.

This commit is contained in:
Joachim Bauch 2024-02-27 08:52:20 +01:00
parent 8385211fa2
commit 1f8b536c8a
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 5 additions and 5 deletions

View file

@ -197,11 +197,11 @@ func (m *DnsMonitor) Add(target string, callback DnsMonitorCallback) (*DnsMonito
} }
hostname = parsed.Host hostname = parsed.Host
} else { } else {
// Hostname with optional port passed. // Hostname only passed.
hostname = target hostname = target
if h, _, err := net.SplitHostPort(target); err == nil { }
hostname = h if h, _, err := net.SplitHostPort(hostname); err == nil {
} hostname = h
} }
m.mu.Lock() m.mu.Lock()

View file

@ -240,7 +240,7 @@ func TestDnsMonitor(t *testing.T) {
rec1 := newDnsMonitorReceiverForTest(t) rec1 := newDnsMonitorReceiverForTest(t)
rec1.Expect(ips1, ips1, nil, nil) rec1.Expect(ips1, ips1, nil, nil)
entry1, err := monitor.Add("https://foo", rec1.OnLookup) entry1, err := monitor.Add("https://foo:12345", rec1.OnLookup)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }