Can I act on the size of the response returned by the Backend Service (Response Size (bytes))?
Short answer
Yes, on the HTTP vService and only in the response stage. The Response Size (bytes) condition compares the size of the response body with an integer in bytes using the Less than, Equals to, Greater than or Range operator; headers are not counted, and the value is read from the Content-Length reported by the Backend Service. The condition is listed only in actions whose Execution Level field is On Response: it is used to add or change a header in the response (Add HTTP Header, Set HTTP Header), to block the response (Block) or to not write the record to the log (Conditional Silent Log). Since the Backend Service selection has already been made when the response arrives, it does not appear in Conditional Backend Services blocks; it is also not used with actions that run in the request stage, such as Bandwidth Limitation.
Background
An HTTP response consists of headers and a body. The server usually reports the size of the body in advance with the Content-Length header. Content whose size is not known in advance, however, is sent in parts (Transfer-Encoding: chunked); in this case, the total size becomes known only at the end of the response.
Problem: The Size of the Response Is Not Known When the Request Arrives
It may be wanted to add separate headers to large file downloads, to not forward responses larger than expected to the client, or to leave very small responses out of the log. The size of the response is known only after the Backend Service responds; for this reason, the decision is made not in the request stage but with actions that run in the response stage. Which Backend Service will handle the request, on the other hand, cannot be changed based on the response size, because it is selected before the response arrives (Can I make decisions based on backend response time or response status code?).
Solution: Three Methods
The three methods bind the same Response Size (bytes) condition to different On Response actions, and they can also be applied together.
| Your situation | Suitable method |
|---|---|
I want to add a header to, or change a header in, responses of a certain size (e.g. Cache-Control for large files) | Method 1: Add HTTP Header / Set HTTP Header (On Response) |
| I want responses larger than expected not to be forwarded to the client | Method 2: Block (On Response) |
| I want responses of a certain size not to be written to the log | Method 3: Conditional Silent Log (On Response) |
Method 1: Add HTTP Header / Set HTTP Header (On Response) Recommended
- How it works When the response of the Backend Service arrives, the body size is compared with the condition; if the condition is met, the header is added or changed before the response is forwarded to the client.
- Where it is openedLoad Balancer → Conditions → Response Size (bytes) · Load Balancer → Actions · vService form → Details → Actions
- Requirement The Backend Service returning responses that report
Content-Length - vService type HTTP
Step-by-Step Configuration
The condition form is opened with Load Balancer → Conditions → Add (how to add).
Condition Name is entered (e.g. yanit-1mb-ustu) and Criteria = Response Size (bytes) is selected. The Operator field opens with Equals to selected and the value empty; the operator is selected and an integer in bytes is entered:
| Operator | Example | Matching response |
|---|---|---|
| Greater than | 1048576 | Body larger than 1 MB |
| Less than | 1024 | Body smaller than 1 KB |
| Range | 102400 - 1048576 | Body between 100 KB and 1 MB, both limits included |
| Equals to | 0 | Body empty |
The Add button is clicked.
The Load Balancer → Actions → Add steps are followed.
Action Name is entered, and Action Type = Add HTTP Header (to add a header) or Set HTTP Header (to change the value of the header) is selected. Execution Level = On Response is selected; if no selection is made, the action runs in the request stage and the Response Size (bytes) condition does not appear in the Conditions list. Execution Level cannot be changed after saving.
The header name and value are entered in the Header to Add and Header Content fields (e.g. Cache-Control · public, max-age=86400); the condition from step 2 is selected in the Conditions field.
The Add button is clicked.
The Load Balancer → Load Balancer vService List steps are followed, the HTTP vService is opened and the Details button at the top of the form is clicked.
The created action is selected in the Actions field.
The Save button is clicked.
Verification
The file with a size above the threshold is requested and the response headers are checked; the command is repeated with the address of a file whose size is below the threshold.
curl -s -o /dev/null -D - http://203.0.113.10/indir/buyuk.zipCache-Control: public, max-age=86400 in the response of the large file · absent for the small fileMethod 2: Block (On Response)
- How it works The response that fits the condition is not forwarded to the client; the client is answered with the status code selected in the action (default 403), or receives no response if Silent Drop is selected.
- Where it is openedLoad Balancer → Actions · vService form → Details → Actions
- Requirement The Response Size (bytes) condition created in steps 1–3 of Method 1
- vService type HTTP
Step-by-Step Configuration
The Load Balancer → Actions → Add steps are followed.
Action Type = Block and Execution Level = On Response are selected. Standard or Silent Drop is selected in the Deny Type field (Tarpit is not offered in the response stage); with Standard, the Status Code is set. The Response Size (bytes) condition is selected in the Conditions field; to cover only a specific path, it is combined with the Path condition with and.
The Add button is clicked.
Steps 8–10 of Method 1 are applied.
Verification
A response with a size above the threshold is requested.
curl -sI http://203.0.113.10/api/exportHTTP/1.1 403 (Standard, default code) · responses below the threshold return unchangedMethod 3: Conditional Silent Log (On Response)
- How it works The record of the response that fits the condition is not written to the HTTP logs of the vService; the response itself is forwarded to the client unchanged.
- Where it is openedLoad Balancer → Actions · vService form → Details → Actions
- Requirement The Response Size (bytes) condition created in steps 1–3 of Method 1
- vService type HTTP
Step-by-Step Configuration
The Load Balancer → Actions → Add steps are followed.
Action Type = Conditional Silent Log and Execution Level = On Response are selected; since the Conditions field is reset when the field is changed, the condition is added after this selection. The Response Size (bytes) condition (e.g. Equals to 0) is selected in the Conditions field.
The Add button is clicked.
Steps 8–10 of Method 1 are applied.
Verification
After a request that fits the condition is sent, Refresh is clicked on the Logs & Tracking → HTTP Logs screen of the vService.
The record of the response that fits the condition is not in the list; the other requests are recordedCommon Mistakes
Responses That Do Not Report Content-Length
If the Backend Service sends the response in parts (chunked/streaming) without Content-Length, the total size is not known; the value reflects the data received up to that moment. These responses can match Less than thresholds by mistake, and may not match Greater than and Range thresholds. The size condition is reliable only for responses that report Content-Length.
- Leaving Execution Level at On Request. The Response Size (bytes) condition is evaluated only in the response stage; unless Execution Level On Response is selected, the condition does not appear in the Conditions list. The field cannot be changed after saving; if it was selected wrongly, a new action is defined.
- Trying to select a Backend Service based on the response size. The Backend Service is selected in the request stage; conditions of the response stage are not listed in Conditional Backend Services blocks.
- Trying to apply Bandwidth Limitation to large downloads. Bandwidth Limitation runs only in the request stage and does not accept conditions of the response stage; limiting the download speed based on the response size cannot be done with this condition.
- Thinking that the headers are also counted. The value is only the body size; the response headers are not included.
- Confusing it with the request size condition. For the size of the request coming from the client, the Request Size (bytes) condition is used (Can I block large requests (e.g. above a certain size)?).
How it is done in the documentation
