<p><a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=184809" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/miconda">@miconda</a> I think correct way will be:</p>
<pre><code>        tps_remove_headers(msg, HDR_RECORDROUTE_T);

        if(msg->first_line.u.reply.statuscode>100
                                && msg->first_line.u.reply.statuscode<200
                                && msg->contact==NULL) {
                                        contact_keep = 1;
        }

        /* keep contact without updates for redirect responses sent out */
        if(contact_keep==0 && (msg->first_line.u.reply.statuscode<300
                        || msg->first_line.u.reply.statuscode>=400)) {
                tps_remove_headers(msg, HDR_CONTACT_T);

                if(direction==TPS_DIR_DOWNSTREAM) {
                        tps_reinsert_contact(msg, &stsd, &stsd.as_contact);
                } else {
                        tps_reinsert_contact(msg, &stsd, &stsd.bs_contact);
                }
        }                
        
        tps_reappend_rr(msg, &btsd, &btsd.x_rr);
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1720#issuecomment-441057459">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZX1tMVwe3CNhIH16Iryy6VH_R_rpks5uxr3PgaJpZM4YbweF">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZUEP6-7auYQHhcVi34s4N0W1f2jWks5uxr3PgaJpZM4YbweF.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@sergey-vb in #1720: @miconda I think correct way will be:\r\n```\r\n        tps_remove_headers(msg, HDR_RECORDROUTE_T);\r\n\r\n        if(msg-\u003efirst_line.u.reply.statuscode\u003e100\r\n                                \u0026\u0026 msg-\u003efirst_line.u.reply.statuscode\u003c200\r\n                                \u0026\u0026 msg-\u003econtact==NULL) {\r\n                                        contact_keep = 1;\r\n        }\r\n\r\n        /* keep contact without updates for redirect responses sent out */\r\n        if(contact_keep==0 \u0026\u0026 (msg-\u003efirst_line.u.reply.statuscode\u003c300\r\n                        || msg-\u003efirst_line.u.reply.statuscode\u003e=400)) {\r\n                tps_remove_headers(msg, HDR_CONTACT_T);\r\n\r\n                if(direction==TPS_DIR_DOWNSTREAM) {\r\n                        tps_reinsert_contact(msg, \u0026stsd, \u0026stsd.as_contact);\r\n                } else {\r\n                        tps_reinsert_contact(msg, \u0026stsd, \u0026stsd.bs_contact);\r\n                }\r\n        }                \r\n        \r\n        tps_reappend_rr(msg, \u0026btsd, \u0026btsd.x_rr);\r\n```"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1720#issuecomment-441057459"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1720#issuecomment-441057459",
"url": "https://github.com/kamailio/kamailio/issues/1720#issuecomment-441057459",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [kamailio/kamailio] 180 Ringing without Contact with TOPOS enabled (#1720)",
"sections": [
{
"text": "",
"activityTitle": "**Sergey Basov**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@sergey-vb",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1720,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1720#issuecomment-441057459"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 409929605\n}"
}
],
"themeColor": "26292E"
}
]</script>