Forum Discussion

Yaniv_99962's avatar
Yaniv_99962
Icon for Nimbostratus rankNimbostratus
May 23, 2017

remove HTTP header based on its value

Lets say I have a client sending multiple headers with same name but different values. How can i remove just one of these headers if it's value is equal to something i'm looking for?

For example:

GET / HTTP/1.1
Test: a
Test: b
Test: c
Test: d

how can I remove just "Test: c" ?

Thanks in advanced

  • Anesh's avatar
    Anesh
    Icon for Cirrostratus rankCirrostratus

    Try the below

    when HTTP_RESPONSE { 
       foreach header_name [HTTP::header names] { 
          if {[HTTP::header value Test] equals "c"}{ 
             HTTP::header remove $header_name 
          }
       }
    }
    
  • Hello Yaniv,

    try this

     set nTEST [HTTP::header count "TEST"]
    
     if { $nTEST eq "0" } {
          log local0. "Nothing to do => No TEST header found"
     } else {
        set TESTValueList [HTTP::header values "TEST"]
            set firstloop 0
            foreach TESTValue $TESTValueList {
    
                    if { $firstloop eq "0"} {
                            HTTP::header remove "TEST"
                    }
    
                    if { $TESTValue eq "c"} {
                            nothing to do
                            log local0. "Removed -> TEST: $TESTValue"
                    } else {
                            HTTP::header insert TEST $TESTValue
                            log local0. "Inserted -> TEST: $TESTValue"
                    }
    
                    set firstloop 1
            }
      }