# Limit HTTP Request on LTM

**URL:** <https://community.f5.com/t/limit-http-request-on-ltm/47124>\
**Category:** Technical Forums\
**Tags:** irules, application-delivery\
**Created:** [November 14, 2020, 8:49pm UTC](https://community.f5.com/t/limit-http-request-on-ltm/47124 "2020-11-14T20:49:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmetnuman](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@ahmetnuman](https://community.f5.com/u/ahmetnuman)\
**Post date:** [November 14, 2020, 8:49pm UTC](https://community.f5.com/t/limit-http-request-on-ltm/47124/1 "2020-11-14T20:49:34Z")

</div>

Hello ,

I want to limit total number of HTTP request on our web application uri (like /test/test1). Is there any irule to accomplish this ?

Thank you very much

---

<div class="post-metadata">

**Author:** ![Dario\_Garrido](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@Dario\_Garrido](https://community.f5.com/u/Dario_Garrido)\
**Post date:** [November 14, 2020, 10:38pm UTC](https://community.f5.com/t/limit-http-request-on-ltm/47124/2 "2020-11-14T22:38:23Z")

</div>

Hello.

You can use this approach replacing those global variables by table variables (for being CMP compatible).

[https://devcentral.f5.com/s/articles/http-session-limit-1](https://devcentral.f5.com/s/articles/http-session-limit-1)

> **[table](https://clouddocs.f5.com/api/irules/table.html)**

The basic idea is to increase the counter value when HTTP\_REQUEST is executed and decrease the same variable when HTTP\_RESPONSE\_RELEASE is executed.

Regards,

Dario.

---

<div class="post-metadata">

**Author:** ![ahmetnuman](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@ahmetnuman](https://community.f5.com/u/ahmetnuman)\
**Post date:** [November 15, 2020, 8:57pm UTC](https://community.f5.com/t/limit-http-request-on-ltm/47124/3 "2020-11-15T20:57:02Z")

</div>

Hello Dario thank you very much for reply,

I solved my problem via using following irule, it works very well, this i rule briefly count the coming http request on the vip ip if the uri’s are /bla/blaservice or /bla/blaservices, then if maximum rate is reached within 2 sec, then bigip response http 2oo status code with blank pages.

```tcl
when RULE_INIT {
    set static::maxRate 4000
    set static::windowSecs 2
}
when HTTP_REQUEST {
        
    if { [HTTP::uri] == "/blablaservice" or [HTTP::uri] == "/blablaservices/"} {
        # set variables
        set limiter [string tolower [HTTP::uri]]
        set vip_limitervar [IP::local_addr]:$limiter
        set get_count [table key -count -subtable $vip_limitervar]
        # main condition
        if { $get_count < $static::maxRate } {
            incr get_count 1
             table set -subtable $vip_limitervar $get_count $vip_limitervar indefinite $static::windowSecs
        } else {
            #log local0. "$vip_limitervar has exceeded the number of requests allowed."
            HTTP::respond 200 content ""
            return
        }
    }
}

```
