Forum Discussion

MSZ_221163's avatar
MSZ_221163
Icon for Nimbostratus rankNimbostratus
Oct 24, 2017

Header Value: Empty

Is there any way around to accept empty value of any specific HEader?

 

Best Wishes,

 

Note: Header name with no header value: If we disable this check then it will be applicable to the all Headers.

 

2 Replies

  • Is this what you're looking for?

        if {([HTTP::header exists "your-header-name"]) && ([HTTP::header value "your-header-name"] eq "")} {
            do something
    }
    
  • Does this actually work as written? According to the API, HTTP::header exists returns true if the named header is present and not empty on the request or response. And HTTP::header value will return an null string if the header's value is null or if the header is not present. (Emphases mine.) So it seems to me that if the iRule needs to take action if the header is present but empty, HTTP::header exists is useless and HTTP::header value doesn't distinguish between an empty header an a missing one.

    Would something like this work?

    when HTTP_REQUEST {
        
        # The lsearch function returns a zero-based index of a string's position within a list,
        # or -1 if the string is not present.
        
        # So if the search string is in the zeroth (i.e., first) position, a test based on that alone
        # would return false. Adding one to the lsearch result provides true if the string is present
        # and false only if the string is absent from the list.
        
        if { ( [lsearch [HTTP::header names] "your-header" ] + 1 ) && ( [HTTP::header "your-header"] eq "") } {
            do something
        }
    }

    I haven't tested this but it appears to be syntactically correct.