# Remove Whitespace from HTTP Response Payload

**URL:** <https://community.f5.com/t/remove-whitespace-from-http-response-payload/67045>\
**Category:** Community CodeShare\
**Tags:** irules, devops, stream, http\
**Created:** [January 30, 2015, 1:16pm UTC](https://community.f5.com/t/remove-whitespace-from-http-response-payload/67045 "2015-01-30T13:16:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [January 30, 2015, 1:16pm UTC](https://community.f5.com/t/remove-whitespace-from-http-response-payload/67045/1 "2015-01-30T13:16:39Z")

</div>

**Problem this snippet solves:**

Summary: Strip extraneous white space from HTML in the HTTP response payload Here is a simple iRule which uses a stream filter and STREAM::expression based iRule to two or more consecutive whitespace characters with a space. It hasn’t been tested in production so try it on a test virtual server or test unit first!

**Code :**

```auto
when HTTP_REQUEST {

       # Prevent server compression
       HTTP::header remove "Accept-Encoding"

       # Disable the stream filter by default
       STREAM::disable
}
when HTTP_RESPONSE {

       # Check if server response is text based
       if { [HTTP::header Content-Type] contains "text" }{

              # Set the stream expression to match two or more consecutive whitespace characters
              # Replace them with a single space
              STREAM::expression @\s+@ @}
              STREAM::enable
       }
}

```

---

<div class="post-metadata">

**Author:** ![JRahm](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/jrahm/32/3327_2.png) [@JRahm](https://community.f5.com/u/JRahm)\
**Post date:** [January 30, 2015, 1:17pm UTC](https://community.f5.com/t/remove-whitespace-from-http-response-payload/67045/2 "2015-01-30T13:17:02Z")

</div>

Contributed by hoolio.
