<HTML><BODY><div>
<div>Hello Ben,</div>

<div>Thank you for your advices!<br>
 </div>

<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">Четверг, 26 сентября 2019, 21:16 +03:00 от Ben Newlin <ben.newlin@genesys.com>:<br>
 
<div id="">
<div class="js-helper js-readmsg-msg">
<style type="text/css">
</style>
<div>
<div id="style_15695217730526521750_BODY">
<div class="class_1569555018">
<div class="WordSection1_mailru_css_attribute_postfix">
<p class="MsoNormal_mailru_css_attribute_postfix">Oleg,</p>

<p class="MsoNormal_mailru_css_attribute_postfix"> </p>

<p class="MsoNormal_mailru_css_attribute_postfix">OpenSIPS stores all the changes you make to the INVITE and applies them all together right before sending it out. This is to be more efficient. So you cannot usually see these types of changes during processing. This means if you want to keep using those headers in your script you need to remember them yourself.</p>

<p class="MsoNormal_mailru_css_attribute_postfix"> </p>

<p class="MsoNormal_mailru_css_attribute_postfix">The easiest way to do this from your code is to just access the same $json variable in the BALANCE route. JSON variables in OpenSIPS are just like $var in that they are persistent within an OpenSIPS process [1] (so make sure you initialize!). So as long as you are not calling any async function in between, the values will all still be there.</p>

<p class="MsoNormal_mailru_css_attribute_postfix"> </p>

<p class="MsoNormal_mailru_css_attribute_postfix">Alternatively, you can store the values in AVPs [2]. Assuming you are using TM, AVPs are attached to the transaction and will persist through branches and replies, in case you need the values there as well. AVPs are stacks, so the model I have used for data like this is to have 2 AVPs – one for the keys and one for the values – and keep them in sync.</p>

<p class="MsoNormal_mailru_css_attribute_postfix"> </p>

<p class="MsoNormal_mailru_css_attribute_postfix">[1] - <a href="https://opensips.org/html/docs/modules/2.4.x/json.html#pv_json" rel="noopener noreferrer" target="_blank"> https://opensips.org/html/docs/modules/2.4.x/json.html#pv_json</a></p>

<p class="MsoNormal_mailru_css_attribute_postfix">[2] - <a href="https://www.opensips.org/Documentation/Script-CoreVar-2-4#toc2" rel="noopener noreferrer" target="_blank"> https://www.opensips.org/Documentation/Script-CoreVar-2-4#toc2</a></p>

<p class="MsoNormal_mailru_css_attribute_postfix"> </p>

<p class="MsoNormal_mailru_css_attribute_postfix"><span style="color:black">Ben Newlin </span></p>

<p class="MsoNormal_mailru_css_attribute_postfix"> </p>

<div style="border-top:solid #b5c4df 1.0pt; border:none; padding:3.0pt 0in 0in 0in">
<p class="MsoNormal_mailru_css_attribute_postfix"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">Users <<a href="/compose?To=users%2dbounces@lists.opensips.org">users-bounces@lists.opensips.org</a>> on behalf of Oleg Podguyko via Users <<a href="/compose?To=users@lists.opensips.org">users@lists.opensips.org</a>><br>
<b>Reply-To: </b>Oleg Podguyko <<a href="/compose?To=podguiko@mail.ru">podguiko@mail.ru</a>>, OpenSIPS users mailling list <<a href="/compose?To=users@lists.opensips.org">users@lists.opensips.org</a>><br>
<b>Date: </b>Thursday, September 26, 2019 at 1:49 PM<br>
<b>To: </b>"users@lists.opensips.org" <<a href="/compose?To=users@lists.opensips.org">users@lists.opensips.org</a>><br>
<b>Subject: </b>[OpenSIPS-Users] Take the value of the newly added SIP X-header for the log</span></p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix">Hello everebody!</p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix">My opensips works as proxy. Get INVITE from one side and communicates with a remote web server via rest. Opensips sends a request to the web server and receives a lot of custom data, which it converts to SIP X-header. In the end I get 10 different SIP X-headers</p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix">$var(i) = 0; <br>
            while( $json(resp/headers[$var(i)]) )<br>
            {<br>
                $var(header)=$json(resp/headers[$var(i)]/header);<br>
                $var(value)=$json(resp/headers[$var(i)]/value);<br>
                $var(i) = $var(i) + 1;           <br>
                # add sip headers<br>
                append_hf("$var(header):$var(value)\r\n");<br>
            } <br>
        route(BALANCE);<br>
        route(RELAY);  </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> Everything works. Now, In the next route (BALANCE), I want to output the header that was just added to the log</p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"><span style="font-size:10.0pt;font-family:Menlo;color:#333333;background:#F8F8F8">xlog("L_INFO", "$X-My-Custom-Header: $(hdr(X-My-Custom-Header))");</span></p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix">But in the log I always see null. Although in the INVITE wich opensips sends, all SIP X-header in place. </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix">Does this mean I can't get the value of the newly added SIP X-header? What should I do to get these values?</p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<p class="MsoNormal_mailru_css_attribute_postfix"> </p>
</div>

<div>
<div>
<div>
<p class="MsoNormal_mailru_css_attribute_postfix">--<br>
Олег Подгуйко</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
 

<div> </div>

<div data-signature-widget="container">
<div data-signature-widget="content">
<div>--<br>
Олег Подгуйко</div>
</div>
</div>

<div> </div>
</div>
</BODY></HTML>