Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Irule for layer 7 policy | Stream

warlock
Nimbostratus
Nimbostratus

i am doing layer 7 load balancing based on the URI. I have the below script i rule which works fine for the one VIP one URL but now since there is layer 7 policy applied i want irule to run only if the URI matches the condition. I tried if condition in HTTP _request after WHEN but its applied on all the URL in VIP.

 

 

Irule

 

When HTTP_REQUEST {

STREAM:: DISABLE

}

When HTTP_RESPONSE {

set search "<head>"

set replace "<script><head>"

STREAM:: expression @$search@$replace@

STREAM::ENABLE

}

2 REPLIES 2

cjunior
Nacreous
Nacreous

Hello,

You can combine LTM policy + iRule to insert content to certain policy rule condition.

e.g.

LTM Policy:

rule1

  Condition:

  "HTTP URI" "full string" "is" "any of" "/my_path_to_reqwrite" at "request" time.

  Action:

  "Set variable" named "doInsertScriptRule" equal to "1" at "request" time.

"Forward traffic" to "pool" "pool_1" at "request" time.

rule2

  Condition:

  "HTTP URI" "full string" "is" "any of" "/other_paths" at "request" time.

  Action:

"Forward traffic" to "pool" "pool_2" at "request" time.

LTM iRule:

when HTTP_REQUEST {
  if { [info exists doInsertScriptRule] } {
    HTTP::header remove "Accept-Encoding"
  }
  STREAM::disable
}
when HTTP_RESPONSE {
  if { [info exists doInsertScriptRule] && [HTTP::header value Content-Type] contains "text" } {
    set search "<head>"
    set replace "<head><script>"
    STREAM::expression @$search@$replace@
    STREAM::enable
  }
  unset -nocomplain doInsertScriptRule
}

The [info exists variable] check if variable was set before. 

As LTM policy runs first, it's possible to check for that variable on iRule.

It means that if you don't set a variable in LTM policy, the iRule will not run the string search/replace, than, you must set the variable only for URI you need to.

Best regards

Darwish
Nimbostratus
Nimbostratus

Administrators of traditional hardware application walmartone wire delivery controllers (ADCs) are often faced with use cases that the rule sets provided by ADC vendors don’t cover, and certainly not at the necessary fine‑grained level of control over how requests and responses are processed.