HTTP::payload

Description

Queries for or manipulates HTTP payload (content) information. With this command, you can retrieve content, query for content size, or replace a certain amount of content. The content does not include the HTTP headers.
This command seems to only be available in very specific events like HTTP_REQUEST_DATA and HTTP_RESPONSE_DATA. It doesn’t work in events such as APM’s ACCESS_SESSION_STARTED event, even though that event comes later in the pipeline than events like HTTP_REQUEST (where the HTTP::collect method is called) and HTTP_REQUEST_DATA (which is the point when we have data available for HTTP::payload to retrieve). One option for using payload data in later events is to call HTTP::payload during the HTTP_REQUEST_DATA, parse out what you want, and then put it in variables for use in the later pipeline events.
Note: Having many HTTP::collect across multiple iRules is not a supported operation and should be avoided. The reason is that when performing actions with the collected data (like HTTP::retry or HTTP::respond) will implicitly cause the further operations against a collected data to break since it has been already released.

Syntax

HTTP::payload <length>
HTTP::payload <offset> <length>
HTTP::payload length
HTTP::payload rechunk
HTTP::payload unchunk
HTTP::payload replace <offset> <length> <string>

HTTP::payload <length>

  • Returns the content that the HTTP::collect command has collected thus far, up to the number of bytes specified. If you do not specify a size, the system returns the entire collected content.

HTTP::payload <offset> <length>

  • Returns the content that the HTTP::collect command has collected thus far from the specified offset, up to the number of bytes specified.

HTTP::payload length

  • Returns the size of the content that has been collected thus far, in bytes.

HTTP::payload rechunk

  • Will cause the payload to be chunked on output.
  • This subcommand was added in v9.4.0, and is only valid if selective response chunking is being used.
  • Note: This function is callable, but will not work as expected in the HTTP_REQUEST_SEND event

HTTP::payload unchunk

  • Will cause the payload to be chunked on output if and only if it is chunked on input.
  • This subcommand was added in v9.4.0, and is only valid if selective response chunking is being used.
  • Note: This function is callable, but will not work as expected in the HTTP_REQUEST_SEND event

HTTP::payload replace

  • Replaces the amount of content that you specified with the argument, starting at with , adjusting the Content-Length header appropriately.
  • To clarify, the length argument should be the length of original content to replace. In order to replace the entire payload, the offset should be 0 and the length should be the original size in bytes of the payload.
  • Note that the argument will be interpreted as a byte array. If it is actually a UTF-8 string with multibyte characters, the output will not be what you expect. In order to prepare a UTF-8 string for use as input to HTTP::payload replace, you should first run ‘binary scan c* throwawayvariable’.
  • Note: This function is callable, but will not work as expected in the HTTP_REQUEST_SEND event

Examples

when HTTP_RESPONSE {
   if {[HTTP::status] == 205}{
      HTTP::collect [HTTP::header Content-Length]
      set clen [HTTP::header Content-Length]
   }
}

when HTTP_RESPONSE_DATA {
   HTTP::respond 200 content [HTTP::payload]
}

when HTTP_RESPONSE_DATA {
    regsub -all "oursite" [HTTP::payload] "oursitedev" newdata
    log "Replacing payload with new data."
    HTTP::payload replace 0 $clen $newdata
    HTTP::release
}