Fortinet white logo
Fortinet white logo
8.0.0

Data Collect

Data Collect

HTTP:collect()

HTTP:collect() function instructs FortiWeb to buffer and make available the HTTP request or response body for inspection in subsequent script events. This function can only be used in the HTTP_REQUEST and HTTP_RESPONSE events.

Syntax
HTTP:collect(size)
size

The number of bytes to collect from the HTTP body.

  • If omitted or set to -1, FortiWeb will collect up to the full length of the body, or until the maximum cached length is reached.

  • If a positive integer is specified, FortiWeb will collect that many bytes before triggering the HTTP_DATA_REQUEST or HTTP_DATA_RESPONSE event.

  • This enables partial body inspection and early triggering of body processing logic.

Availability
  • Events: HTTP_REQUEST, HTTP_RESPONSE

  • Applies to both request and response bodies depending on the context.

Example: Full Body Collection
when HTTP_REQUEST {
    if HTTP:header(“content-type”) == text/css
        HTTP::collect()
    end
}
when HTTP_DATA_REQUEST {
    local body_str = HTTP:body()
    debug("body = %s", body_str)
}
Example: Partial Body Collection
when HTTP_REQUEST {
    HTTP:collect(32)  -- collect first 32 bytes of the body
}

when HTTP_DATA_REQUEST {
    local body_sample = HTTP:body(0, 32)
    if body_sample then 
        debug("partial collect body information, partial body = %s", body sample)
    end
}

Notes

  • Specifying a partial size can help reduce latency or processing overhead when only a small portion of the body is needed to make decisions.

  • When partial collection is used, the HTTP_DATA_REQUEST or HTTP_DATA_RESPONSE event is triggered as soon as the specified number of bytes is available.

  • This function is often used in conjunction with:

    • HTTP:body(offset, length)

    • debug() logging

Data Collect

Data Collect

HTTP:collect()

HTTP:collect() function instructs FortiWeb to buffer and make available the HTTP request or response body for inspection in subsequent script events. This function can only be used in the HTTP_REQUEST and HTTP_RESPONSE events.

Syntax
HTTP:collect(size)
size

The number of bytes to collect from the HTTP body.

  • If omitted or set to -1, FortiWeb will collect up to the full length of the body, or until the maximum cached length is reached.

  • If a positive integer is specified, FortiWeb will collect that many bytes before triggering the HTTP_DATA_REQUEST or HTTP_DATA_RESPONSE event.

  • This enables partial body inspection and early triggering of body processing logic.

Availability
  • Events: HTTP_REQUEST, HTTP_RESPONSE

  • Applies to both request and response bodies depending on the context.

Example: Full Body Collection
when HTTP_REQUEST {
    if HTTP:header(“content-type”) == text/css
        HTTP::collect()
    end
}
when HTTP_DATA_REQUEST {
    local body_str = HTTP:body()
    debug("body = %s", body_str)
}
Example: Partial Body Collection
when HTTP_REQUEST {
    HTTP:collect(32)  -- collect first 32 bytes of the body
}

when HTTP_DATA_REQUEST {
    local body_sample = HTTP:body(0, 32)
    if body_sample then 
        debug("partial collect body information, partial body = %s", body sample)
    end
}

Notes

  • Specifying a partial size can help reduce latency or processing overhead when only a small portion of the body is needed to make decisions.

  • When partial collection is used, the HTTP_DATA_REQUEST or HTTP_DATA_RESPONSE event is triggered as soon as the specified number of bytes is available.

  • This function is often used in conjunction with:

    • HTTP:body(offset, length)

    • debug() logging