Forum Discussion

asamadyar's avatar
asamadyar
Icon for Nimbostratus rankNimbostratus
Apr 11, 2022

Remove values of a response header

Hi everybody,

I need to remove the values of a response header. For example:

access-control-allow-headers    ----->  X-Request-UUID, X-Web-Optimize-Response, X-Web-Client-Id, X-Web-City-Id, X-Web-ClientI

 

I need to remove "X-Web-City-Id" and keep everything as they are.

I couldn`t find a related iRule. 

I would appreciate it if somebody could help me with this.

 

Best,

Ali

3 Replies

  • Hello Asamadyar.

    If the header is located in the Response, you could remove it with next iRule.

    when HTTP_RESPONSE
    	HTTP::header remove "X-Web-City-Id"
    }

    Take into account that you would need a HTTP profile applied.

     

    • asamadyar's avatar
      asamadyar
      Icon for Nimbostratus rankNimbostratus

      Many thanks, Dario_Garrido 

      I don`t want to remove the header; I need to remove one value.

      header ------------------------------------------- value

      x-x-x                                                       t1, t2, t3, t4, t5

       

      And I need to remove, for example, "t3" and keep everything intact in the response header.

      I think your code will completely remove the header (x-x-x).

      • Hello Asamadyar.

        Try with this code

         

        when HTTP_RESPONSE {
        	if { [HTTP::header "access-control-allow-headers"] ne "" } {
        		if { [HTTP::header "access-control-allow-headers"] contains "," }{
        			set acheaders [split [HTTP::header "access-control-allow-headers"] ","]
        			set output ""
        			foreach acheader $acheaders {
        				if { $output eq "" } {
        					if { !($acheader contains "X-Web-City-Id") } { set output "$acheader" }
        				} else {
        					if { !($acheader contains "X-Web-City-Id") } { set output "$output,$acheader" }
        				}
        			}
        			#log local0. "INPUT: [HTTP::header "access-control-allow-headers"]"
        			HTTP::header replace "access-control-allow-headers" $output
        			#log local0. "OUTPUT: [HTTP::header "access-control-allow-headers"]"
        		}
        	}
        }