diff --git a/client.go b/client.go index a0529a1..a8e6a4e 100644 --- a/client.go +++ b/client.go @@ -91,7 +91,10 @@ func clientRequestBuildReq(c *Client, req *sip.Request) error { // A valid SIP request formulated by a UAC MUST, at a minimum, contain // the following header fields: To, From, CSeq, Call-ID, Max-Forwards, // and Via; - ClientRequestAddVia(c, req) + if _, exists := req.Via(); !exists { + // Multi VIA value must be manually added + ClientRequestAddVia(c, req) + } if _, exists := req.From(); !exists { from := sip.FromHeader{ @@ -103,7 +106,9 @@ func clientRequestBuildReq(c *Client, req *sip.Request) error { UriParams: sip.NewParams(), Headers: sip.NewParams(), }, + Params: sip.NewParams(), } + from.Params.Add("tag", sip.GenerateTagN(16)) req.AppendHeader(&from) } @@ -117,6 +122,7 @@ func clientRequestBuildReq(c *Client, req *sip.Request) error { UriParams: req.Recipient.UriParams, Headers: req.Recipient.Headers, }, + Params: sip.NewParams(), } req.AppendHeader(&to) } diff --git a/client_test.go b/client_test.go index 7eeb131..8c86c0c 100644 --- a/client_test.go +++ b/client_test.go @@ -26,7 +26,7 @@ func TestClientRequestBuild(t *testing.T) { from, exists := req.From() assert.True(t, exists) - assert.Equal(t, "\"sipgo\" ", from.Value()) + assert.Equal(t, "\"sipgo\" ;tag="+from.Params["tag"], from.Value()) to, exists := req.To() assert.True(t, exists) diff --git a/sip/headers.go b/sip/headers.go index 2bd6b40..667b9a2 100644 --- a/sip/headers.go +++ b/sip/headers.go @@ -977,7 +977,6 @@ func (h *RecordRouteHeader) cloneFirst() *RecordRouteHeader { // Copy all headers of one type from one message to another. // Appending to any headers that were already there. func CopyHeaders(name string, from, to Message) { - name = HeaderToLower(name) for _, h := range from.GetHeaders(name) { to.AppendHeader(h.headerClone()) } diff --git a/sip/sip.go b/sip/sip.go index c853ba6..3344342 100644 --- a/sip/sip.go +++ b/sip/sip.go @@ -39,10 +39,16 @@ func GenerateBranchN(n int) string { } func generateBranchStringWrite(sb *strings.Builder, n int) { - sb.Grow(len(RFC3261BranchMagicCookie) + 33) + sb.Grow(len(RFC3261BranchMagicCookie) + n + 1) sb.WriteString(RFC3261BranchMagicCookie) sb.WriteString(".") - RandStringBytesMask(sb, 32) + RandStringBytesMask(sb, n) +} + +func GenerateTagN(n int) string { + sb := &strings.Builder{} + RandStringBytesMask(sb, n) + return sb.String() } // DefaultPort returns protocol default port by network.