Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add sip uri port if missing #156

Closed
3 changes: 3 additions & 0 deletions sip/parse_uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestParseUri(t *testing.T) {
})

t.Run("sip case insensitive", func(t *testing.T) {
uri = Uri{}
testCases := []string{
"sip:[email protected]",
"SIP:[email protected]",
Expand All @@ -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{
Expand All @@ -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())
}

})
Expand Down
12 changes: 11 additions & 1 deletion sip/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}