Please help with irule for pool selection based on custom http header

Hi all,

Could someone assist me with an irule that would look at a custom header callled X-Server-Pool. If “xyz” then this pool, if “abc” then this pool, else default.

I think this is a starting point but it doesnt appear to be working

  1. when HTTP_REQUEST {
  2. if { [HTTP::header exists X-SERVER-POOL] and [HTTP::header X-SERVER-POOL] equals “xyz” } {
  3. pool xyz
  4. } elseif [HTTP::header exists X-SERVER-POOL] and [HTTP::header X-SERVER-POOL] equals “abc” } {
  5. pool abc
  6. }
  7. }
  8. }

If no header exists it would hit default pool assigned to vip?

Hi sandman748,

Can you look logs with this:

when HTTP_REQUEST {
	if { [HTTP::header exists X-SERVER-POOL] } {
		log local0. "X-Server-Pool: [HTTP::header X-SERVER-POOL]"
		
		switch [HTTP::header X-SERVER-POOL] {
			"xyz" { pool xyz }
			"abc" { pool abc }
		}
	}
}

If no header exists, it hits the default pool. If no default pool exists, it drops. You can add default pool configuration in iRule with using else or switch.

when HTTP_REQUEST {
	if { [HTTP::header exists X-SERVER-POOL] } {
		log local0. "X-Server-Pool: [HTTP::header X-SERVER-POOL]"
		
		switch [HTTP::header X-SERVER-POOL] {
			"xyz" { pool xyz }
			"abc" { pool abc }
			default { defaultpool }
		}
	}
}