Skip to content

Commit 043b56b

Browse files
authored
fix(siptest): reuse CallID when sending a second invite in case of 407# (#432)
1 parent a9ff2af commit 043b56b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/siptest/client.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,21 @@ func (c *Client) Dial(ip string, uri string, number string, headers map[string]s
270270
authHeaderVal = ""
271271
req *sip.Request
272272
resp *sip.Response
273+
callID string
273274
)
274275

275276
for {
276-
req, resp, err = c.attemptInvite(ip, uri, number, offer, authHeaderVal, headers)
277+
req, resp, err = c.attemptInvite(ip, uri, number, offer, authHeaderVal, headers, callID)
277278
if err != nil {
278279
return err
279280
}
280281

282+
if callID == "" {
283+
if callIDHeader := req.CallID(); callIDHeader != nil {
284+
callID = callIDHeader.Value()
285+
}
286+
}
287+
281288
if resp.StatusCode == 407 {
282289
c.log.Debug("auth requested")
283290
if c.conf.AuthUser == "" || c.conf.AuthPass == "" {
@@ -347,8 +354,14 @@ func (c *Client) Dial(ip string, uri string, number string, headers map[string]s
347354
return nil
348355
}
349356

350-
func (c *Client) attemptInvite(ip, uri, number string, offer []byte, authHeader string, headers map[string]string) (*sip.Request, *sip.Response, error) {
357+
func (c *Client) attemptInvite(ip, uri, number string, offer []byte, authHeader string, headers map[string]string, callID string) (*sip.Request, *sip.Response, error) {
351358
req := sip.NewRequest(sip.INVITE, sip.Uri{User: number, Host: uri})
359+
360+
// reuse CallID if not empty
361+
if callID != "" {
362+
req.AppendHeader(sip.NewHeader("Call-ID", callID))
363+
}
364+
352365
req.SetDestination(ip)
353366
req.SetBody(offer)
354367
req.AppendHeader(sip.NewHeader("Content-Type", "application/sdp"))

0 commit comments

Comments
 (0)