Skip to content

Commit

Permalink
fix: add to tag on all responses except 100 #43
Browse files Browse the repository at this point in the history
  • Loading branch information
emiago committed Sep 20, 2023
1 parent 0cb08f8 commit 7ae41e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
16 changes: 10 additions & 6 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ func createSimpleRequest(method sip.RequestMethod, sender sip.Uri, recipment sip
req.AppendHeader(&sip.FromHeader{
DisplayName: strings.ToUpper(sender.User),
Address: sip.Uri{
User: sender.User,
Host: sender.Host,
Port: sender.Port,
User: sender.User,
Host: sender.Host,
Port: sender.Port,
UriParams: sip.NewParams(),
},
Params: sip.NewParams(),
})
req.AppendHeader(&sip.ToHeader{
DisplayName: strings.ToUpper(recipment.User),
Address: sip.Uri{
User: recipment.User,
Host: recipment.Host,
Port: recipment.Port,
User: recipment.User,
Host: recipment.Host,
Port: recipment.Port,
UriParams: sip.NewParams(),
},
Params: sip.NewParams(),
})
callid := sip.CallIDHeader("gotest-" + time.Now().Format(time.RFC3339Nano))
req.AppendHeader(&callid)
Expand Down
17 changes: 10 additions & 7 deletions sip/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,24 @@ func NewResponseFromRequest(
res.AppendHeader(h.headerClone())
}

if statusCode == 100 {
// 8.2.6.2 Headers and Tags
// the response (with the exception of the 100 (Trying) response, in
// which a tag MAY be present). This serves to identify the UAS that is
// responding, possibly resulting in a component of a dialog ID. The
// same tag MUST be used for all responses to that request, both final
// and provisional (again excepting the 100 (Trying)). Procedures for
// the generation of tags are defined in Section 19.3.
switch statusCode {
case 100:
CopyHeaders("Timestamp", req, res)
}

if statusCode == 200 {
default:
if _, ok := res.to.Params["tag"]; !ok {
uuid, _ := uuid.NewV4()
res.to.Params["tag"] = uuid.String()
}
}

// if body != nil {
res.SetBody(body)
// }

res.SetTransport(req.Transport())
res.SetSource(req.Destination())
res.SetDestination(req.Source())
Expand Down

0 comments on commit 7ae41e5

Please sign in to comment.