[OpenSIPS-Users] How to best check a request's method?

Vlad Paiu vladpaiu at opensips.org
Thu Nov 15 10:53:17 CET 2012


Hello,

You assumptions are right :)
 From coding point of view, is_method is more flexible.
 From performance point of view, is_method is faster, since at startup 
it goes through the list and if it contains only well known header 
names, at runtime it will only do binary ops for checking the method, 
instead of checking the actual method string.

Regards,

Vlad Paiu
OpenSIPS Developer
http://www.opensips-solutions.com


On 11/15/2012 10:17 AM, Michael Renzmann wrote:
> Hi.
>
> For the records and just in case anyone stumbles across my post in the
> archives (feel free to ignore it otherwise):
>
>> Let's assume that I want to check whether the current request uses a given
>> method. The following statements would work for that:
>>
>>   1. if (method == INVITE) { ... }
>>   2. if (method == "INVITE") { ... }
>>   3. if (is_method("INVITE")) { ... }
> No one answered so far, so it appears to me this is more or less a
> personal decision thing rather than a real performance issue. :-)
>
> I for me decided to go with is_method(). It's widely used in the demo
> configuration.
>
> Plus: it offers more flexibility when it comes to expanding an existing
> test. Say, if you wanted to expand the statements given as example above
> to also test for SUBSCRIBE requests, for 1 or 2 you would end up with
> something like:
>
>    if ((method == INVITE) || (method == SUBSCRIBE)) { ... }
>
> while with 3 it would be:
>
>    if (is_method("INVITE|SUBSCRIBE")) { ... }
>
> The latter appears to be more intuitive and easier to read, at least for me.
>
> Bye, Mike
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users



More information about the Users mailing list