diff --git a/sip/parse_uri_test.go b/sip/parse_uri_test.go index 33a0fa5..4f54911 100644 --- a/sip/parse_uri_test.go +++ b/sip/parse_uri_test.go @@ -39,6 +39,7 @@ func TestParseUri(t *testing.T) { }) t.Run("sip case insensitive", func(t *testing.T) { + uri = Uri{} testCases := []string{ "sip:alice@atlanta.com", "SIP:alice@atlanta.com", @@ -50,6 +51,7 @@ func TestParseUri(t *testing.T) { assert.Equal(t, "alice", uri.User) assert.Equal(t, "atlanta.com", uri.Host) assert.False(t, uri.IsEncrypted()) + assert.Equal(t, "atlanta.com:5060", uri.HostPort()) } testCases = []string{ @@ -63,6 +65,7 @@ func TestParseUri(t *testing.T) { assert.Equal(t, "alice", uri.User) assert.Equal(t, "atlanta.com", uri.Host) assert.True(t, uri.IsEncrypted()) + assert.Equal(t, "atlanta.com:5061", uri.HostPort()) } }) diff --git a/sip/uri.go b/sip/uri.go index 4c953bb..c0779aa 100644 --- a/sip/uri.go +++ b/sip/uri.go @@ -145,6 +145,16 @@ func (uri *Uri) Addr() string { // HostPort represents host:port part func (uri *Uri) HostPort() string { - p := strconv.Itoa(uri.Port) + transport := TransportTCP + if uri.IsEncrypted() { + transport = TransportTLS + } + + port := uri.Port + if port == 0 { + port = DefaultPort(transport) + } + + p := strconv.Itoa(port) return uri.Host + ":" + p }