Forum Discussion

f5_rocks's avatar
f5_rocks
Icon for Nimbostratus rankNimbostratus
May 06, 2016

Trying to correctly fformat multiple not statements

started with this... when CLIENT_ACCEPTED {event HTTP_REQUEST enable} when HTTP_REQUEST { set MY_HOST [string tolower [HTTP::host]] set MY_URI [string tolower [HTTP::uri]] if {$MY_URI start...
  • Vernon_97235's avatar
    May 07, 2016

    not or not
    probably doesn't mean what you think. Consider
    not A or not B
    . Assuming that A, B and C are mutually exclusive conditions, the statement
    not A or not B
    is true under all of the following conditions:

    • A is true
    • B is true
    • C is true

    That's because

    not A or not B
    is true if: A is not true, if B is not true, or if both are not true. In the first case (
    A is true
    ), B is not true, so the statement matches. In the second case (
    B is true
    ), A is not true, so the statement matches. In the third case, both A and B are not true, so the statement matches. Putting this in terms of your command, consider:

    not ($MY_URI starts_with "/abcd/web/abcdpayment.web/") or not ($MY_URI starts_with "/abcd/web/abcdpaymentprocessing.web/")
    

    If

    $MY_URI
    starts_with "/abcd/web/abcdpayment.web/" this statement actually matches (that is, it evaluates to true) because the condition
    not ($MY_URI starts_with "/abcd/web/abcdpaymentprocessing.web/")
    is in fact true:
    $MY_URI
    does NOT start with "/abcd/web/abcdpaymentprocessing.web/".

    You want

    not and not
    . Consider
    not A and not B
    . According to this:

    • if A is true, the statement is false (because
      not A
      is false)
    • if B is true, the statement is false (because
      not B
      is false)
    • if C is true, the statement is true (because
      not A
      is true and
      not B
      is true)

    Again, matching against your logic:

    not ($MY_URI starts_with "/abcd/web/abcdpayment.web/") and not ($MY_URI starts_with "/abcd/web/abcdpaymentprocessing.web/")
    

    Now, if

    $MY_URI
    starts with "/abcd/web/abcdpayment.web/", this statement is false.

    Incidentally, this is exactly equivalent to:

    not ($MY_URI starts_with "/abcd/web/abcdpayment.web/" or $MY_URI starts_with "/abcd/web/abcdpaymentprocessing.web/")