diff --git a/sgsip/sgsip.go b/sgsip/sgsip.go index c98ee33..3446029 100644 --- a/sgsip/sgsip.go +++ b/sgsip/sgsip.go @@ -1071,17 +1071,21 @@ func SGSIPInviteToACKString(invReq *SGSIPMessage, invRpl *SGSIPMessage, outputSt for _, h := range invReq.Headers { switch h.HType { case HeaderTypeVia: - sList := strings.SplitN(h.Body, ";branch=", 2) - if len(sList) < 2 { + if invRpl.FLine.Code >= 300 { sb.WriteString(h.Name + ": " + h.Body + "\r\n") } else { - idxSCol := strings.Index(sList[1], ";") - if idxSCol < 0 { - sb.WriteString(h.Name + ": " + sList[0] + ";branch=" + - viaBranchCookie + uuid.New().String() + "\r\n") + sList := strings.SplitN(h.Body, ";branch=", 2) + if len(sList) < 2 { + sb.WriteString(h.Name + ": " + h.Body + "\r\n") } else { - sb.WriteString(h.Name + ": " + sList[0] + ";branch=" + - viaBranchCookie + uuid.New().String() + sList[1][idxSCol:] + "\r\n") + idxSCol := strings.Index(sList[1], ";") + if idxSCol < 0 { + sb.WriteString(h.Name + ": " + sList[0] + ";branch=" + + viaBranchCookie + uuid.New().String() + "\r\n") + } else { + sb.WriteString(h.Name + ": " + sList[0] + ";branch=" + + viaBranchCookie + uuid.New().String() + sList[1][idxSCol:] + "\r\n") + } } } case HeaderTypeFrom: