waf file-compress-rule
Use this command to compress specific file types in HTTP replies.
Compression can reduce bandwidth, which can reduce delivery time to end users. Modern browsers automatically decompress files before they display web pages.
You can configure most web servers to compress files when they respond to a request. However, if you do not want to configure each of your web servers separately, or if you want to offload compression for performance reasons, you can configure FortiWeb to do the compression.
When FortiWeb needs to inspect or modify the complete response body, compression applies only to responses with a pre-compressed file size smaller than the max-cache-size setting in System Advanced Settings. If a file exceeds this limit, FortiWeb transmits it uncompressed. You can adjust the maximum file size using the config system advanced command’s max-cache-size setting. For details, see system advanced.
However, if FortiWeb does not need to inspect or modify the full response body, compression applies to all response sizes.
To apply a compression rule, select it in an inline protection profile. For details, see waf web-protection-profile inline-protection.
To use this command, your administrator account’s access control profile must have either w or rw permission to the wafgrp area. For details, see Permissions.
Syntax
config waf file-compress-rule
edit "<rule_name>"
set compression-type {gzip | brotli | zstd}
set compression-level {level1 | level2 | ...}
set exclude-url "<exclusion-rule_name>"
next
end
config content-types
edit "<content-types_id>"
set content-type "<content-type_name>"
end
| Variable | Description | Default |
|
Enter the name of a new or existing rule. The maximum length is 63 characters. To display the list of existing rules, enter:
|
No default. | |
| Enter the index number of the individual entry in the table. The valid range is 1–9,999,999,999,999,999,999. | No default. | |
|
Set the file compression type.
|
No default. | |
|
Set the compression level for the file to be compressed. This option is available only when you select brotli or zstd for the compression-type. Set the compression level based on the selected compression type:
|
No default. | |
|
Enter one of the following content types to compress it:
To compress multiple file types, add each file type in a separate table entry with its own <entry_index>. See Example. |
No default. | |
| Enter the name of an exclusion to use with the rule, if any. For details, see waf exclude-url. The maximum length is 63 characters. | No default. |
Example
This example configures a file compression rule that compresses CSS and HTML files, unless they match one of the URLs in the exception named “Compression Exclusion 1.”
config waf file-compress-rule
edit "file-compress-rule_name"
set compression-type gzip
set compression-level level2
set content-types
edit 1
set content-type text/css
next
edit 2
set content-type text/html
next
end
set exclude-url "Compression Exclusion 1"
next
end