# HTTP\_request and HTTP\_response in same irule?

**URL:** <https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358>\
**Category:** Technical Forums\
**Tags:** irules, big-ip-access-policy-manager-apm, security, devops, application-delivery\
**Created:** [October 2, 2013, 5:13pm UTC](https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358 "2013-10-02T17:13:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mukund\_125243](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Mukund\_125243](https://community.f5.com/u/Mukund_125243)\
**Post date:** [October 2, 2013, 5:13pm UTC](https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358/1 "2013-10-02T17:13:13Z")

</div>

Is it allowed to execute a single irule with a ‘when HTTP\_Request’ and also a ‘when HTTP\_response’ events? I believe in the situation I wish to implement, I can write 2 separate Irules and stack them ( I think I read on this site that they work in the order they are added in). But , I was just curious to know if I can write the ‘when http\_request’ at the top as an event and after closing the loop, use a new when ‘http\_response’ as second part of the irule.

If knowing the situation helps, the plan is to divert traffic to a specific node based on a header value in request, but for calls that don’t have a header value, the BIG-IP should round robin the connection and then add a header value to it during response based on the responding node.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [October 2, 2013, 5:16pm UTC](https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358/2 "2013-10-02T17:16:42Z")

</div>

It is absolutely possible, and perhaps desirable, to put all of your events into a single iRule.

```tcl
when CLIENT_ACCEPTED {
    ...
}
when HTTP_REQUEST {
    ...
}
when HTTP_RESPONSE {
    ...
}
when LB_SELECTED {
    ...
}

```

It’s also worth noting that the order of the events in the iRule is not important.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [October 2, 2013, 5:18pm UTC](https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358/3 "2013-10-02T17:18:35Z")

</div>

the plan is to divert traffic to a specific node based on a header value in request, but for calls that don’t have a header value, the BIG-IP should round robin the connection and then add a header value to it during response based on the responding node.

Just keep in mind that headers are generally not relayed by the client. In other wordsm if you send a header to a client browser, it will not send it back.

---

<div class="post-metadata">

**Author:** ![Mukund\_125243](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Mukund\_125243](https://community.f5.com/u/Mukund_125243)\
**Post date:** [October 2, 2013, 5:27pm UTC](https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358/4 "2013-10-02T17:27:06Z")

</div>

Thanks Kevin. I understand the headers are not going to come back with browser requests - but these are soap calls from a customized solution and I am working with the developers from other side to capture all headers, and preserve a designated one I insert in the subsequent calls. All of this is to mask the fact that an app we run does not share session ids between nodes so round robin breaks calls after login (that have just a valid session id) since they go to a different node. The workaround I proposed is to mark with special header ‘tags’ which will then be attached to their subsequent calls and I route using the irule to the correct node.

---

<div class="post-metadata">

**Author:** ![Mukund\_125243](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Mukund\_125243](https://community.f5.com/u/Mukund_125243)\
**Post date:** [October 2, 2013, 5:32pm UTC](https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358/5 "2013-10-02T17:32:16Z")

</div>

FYI - any alternate suggestions using BigIP are welcome 🙂

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [October 2, 2013, 5:43pm UTC](https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358/6 "2013-10-02T17:43:37Z")

</div>

Your solution is fine if the downstream client is programmed to relay the header. You can alternately use a cookie if the client supports it.

---

<div class="post-metadata">

**Author:** ![Jason\_X\_186825](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@Jason\_X\_186825](https://community.f5.com/u/Jason_X_186825)\
**Post date:** [May 23, 2015, 8:40pm UTC](https://community.f5.com/t/http-request-and-http-response-in-same-irule/19358/7 "2015-05-23T20:40:06Z")

</div>

Hi Mukund, I’m curious how your request & response tagging worked for you? As I have a similar requirement where by I need to log a SOAP request and and it’s corresponding SOAP reply. The iRule I have works in Dev but when deployed into production the association is not maintained.
