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.
|
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_REQUESTorHTTP_DATA_RESPONSEevent 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
-