Skip to content

Commit

Permalink
Merge branch 'fix/add-missing-sip-uri-port-if-missing' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
InnovativeUS committed Dec 5, 2024
2 parents 30197cc + 5754110 commit a662d83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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
}

0 comments on commit a662d83

Please sign in to comment.