# Stream expression for TCP payload

**URL:** <https://community.f5.com/t/stream-expression-for-tcp-payload/4118>\
**Category:** Technical Forums\
**Tags:** irules, big-ip, regex, application-delivery, stream, stream-profile\
**Created:** [November 23, 2016, 3:19pm UTC](https://community.f5.com/t/stream-expression-for-tcp-payload/4118 "2016-11-23T15:19:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan\_239725](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jonathan\_239725](https://community.f5.com/u/jonathan_239725)\
**Post date:** [November 23, 2016, 3:19pm UTC](https://community.f5.com/t/stream-expression-for-tcp-payload/4118/1 "2016-11-23T15:19:39Z")

</div>

So I have been trying to find the most efficient way to detect string patterns within HTTP payloads. I have found out the best way to tackle this (from what I know so far) is to use a stream profile within a HTTP\_RESPONSE event and specify a reg expression. So for my test, I wanted to capture alpha numeric string between 13-16 characters long. I was specifically looking for the value AAAFFFggg12345 and was successful. I did return other values but thats beside the point I’m getting to. This is how I approached it a stream profile within a HTTP\_RESPONSE event.

when HTTP\_REQUEST {

```tcl
STREAM::disable

 if { [HTTP::header value "Host"] equals "winweb1.clearshark.net"} {

        set host [HTTP::header value "Host"]
        HTTP::header remove "Accept-Encoding"

    }

```

}

when HTTP\_RESPONSE {

if {[info exists host]} {

```tcl
if {$host equals "winweb1.clearshark.net"} {

        STREAM::expression {@[a-zA-Z0-9]{13,16}@}
        STREAM::enable

    }

```

} }

when STREAM\_MATCHED {

```tcl
log local0. "Stream matched [STREAM::match]"

```

}

Now…

I want to do the same exact thing, but not within an HTTP\_RESPONSE event. Essentially I want to just look within a TCP payload and find the same string. I have tried the following but have had no success.

when CLIENT\_ACCEPTED {

```tcl
STREAM::disable

```

}

when SERVER\_CONNECTED {

```tcl
TCP::collect

if {[IP::client_addr] equals "172.16.211.103"} {

    log local0. "Stream enabled"
    STREAM::expression {@[a-zA-Z0-9]{13,16}@}
    STREAM::enable

}

```

}

when STREAM\_MATCHED {

```tcl
log local0. "[IP::client_addr]:[TCP::local_port] : Matched : [STREAM::match]"

```

}

I am not seeing the string value AAAFFFggg12345 in my logs like I did when triggering within a HTTP\_RESPONSE event.

I know this seems like a quirky use case but this is simply for a proof of concept for a client. If I can successfully make this happen, I’ll branch off to other tests. But I need to make sure this works first before I move forward.

I appreciate any and all help!

---

<div class="post-metadata">

**Author:** ![jspiglerj2rsolves](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@jspiglerj2rsolves](https://community.f5.com/u/jspiglerj2rsolves)\
**Post date:** [December 1, 2016, 2:33pm UTC](https://community.f5.com/t/stream-expression-for-tcp-payload/4118/2 "2016-12-01T14:33:42Z")

</div>

Still having the same issue. I’m wondering if I can’t detect the string pattern because HTTP compression is enabled. I disable it when I do it with an HTTP event. Any and all wisdom is appreciated! Thanks!

---

<div class="post-metadata">

**Author:** ![crodriguez](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@crodriguez](https://community.f5.com/u/crodriguez)\
**Post date:** [December 1, 2016, 10:48pm UTC](https://community.f5.com/t/stream-expression-for-tcp-payload/4118/3 "2016-12-01T22:48:10Z")

</div>

Certainly if HTTP compression is enabled, you will not be able to detect a string that is part of the HTTP payload unless you decompress first. (Same if it is SSL encrypted - you have to terminate SSL first.)
