Script
within session "INVITE"
{
/*Look for INVITE messages only. This is specified with the extra condition %METHOD="INVITE" in the "where" clause*/
act on request where %DIRECTION="INBOUND" and %ENTRY_POINT="AFTER_NETWORK" and %METHOD="INVITE"
{
/*There could be i.multiple methods in Allow or ii. OPTIONS could be the only method in Allow. If there are multiple methods in Allow, OPTIONS could be i. in the beginning 2. in the middle/the end */
/*If OPTIONS is in the middle/end in Allow, it would be of the form Allow:<Methods>,OPTIONS,<More methods> or Allow:<Methods>,OPTIONS. So, we try to match "Allow" against the regex ,OPTIONS */
if(%HEADERS["Allow"][1].regex_match(", OPTIONS"))then
{
/*<string1>regex_replace(“<regex1>”,”<string2>”) looks for regex1(regular expression) in string1 and replaces it with string2(plain string). Here we replace ,OPTIONS with an empty string, indirectly removing ,OPTIONS*/
%HEADERS["Allow"][1].regex_replace(", OPTIONS","");
}
else
{
/*Nested if-else*/
/*If OPTIONS is in the beginning in Allow, it would be of the form
Allow: OPTIONS,<More methods>. So, we try to match "Allow" against the regex OPTIONS, */
if(%HEADERS["Allow"][1].regex_match(" OPTIONS,"))then
{
/* We replace OPTIONS, with an empty string, indirectly removing OPTIONS,*/
%HEADERS["Allow"][1].regex_replace(" OPTIONS,", "");
}
else
{
/*If OPTIONS is the only method in Allow, it would be of the form
Allow: OPTIONS. So, we try to match "Allow" against the regex OPTIONS */
if(%HEADERS["Allow"][1].regex_match(" OPTIONS"))then
{
/*Since OPTIONS is the only method in Allow, we remove the entire header*/
/*remove(%HEADERS[“<Header-name>”][<Posn>] removes the header specified in
<Header-name> in Position <Posn>.Here we remove the Allow header*/
remove(%HEADERS["Allow"][1]);
}
}
}
}
}