Skip to content

Commit 6fd6470

Browse files
committed
Update request_unbuffered policy README.md file
1 parent 2bfc227 commit 6fd6470

File tree

1 file changed

+88
-8
lines changed
  • gateway/src/apicast/policy/request_unbuffered

1 file changed

+88
-8
lines changed
Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,99 @@
11
# APICast Request Unbuffered
22

3-
This policy allows to disable request buffering
3+
## Description
4+
5+
When enable this policy will dymanically sets the [`proxy_request_buffering: off`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_request_buffering
6+
) directive per service.
7+
8+
9+
## Technical details
10+
11+
By default, NGINX reads the entire request body into memory (or buffers large requests into disk) before proxying it to the upstream server. However, reading bodies can become expensive, especially when requests with large payloads are sent.
12+
13+
For example, when the client sends 10GB, NGINX will buffer the entire 10GB to disk before sending anything to
14+
the upstream server.
15+
16+
When `proxy_request_buffering` is in the chain, request buffering will be disabled and the request body will be sent to the proxied server immediately as it received. This can help minimize time spent sending data to a service and disk I/O for requests with big body. However, there are caveats and corner cases applied, [**Caveats**](#caveats)
17+
18+
The policy also provides a consistent behavior across multiple scenarios like:
19+
20+
```
21+
- APIcast <> upstream HTTP 1.1 plain
22+
- APIcast <> upstream TLS
23+
- APIcast <> HTTP Proxy (env var) <> upstream HTTP 1.1 plain
24+
- APIcast <> HTTP Proxy (policy) <> upstream HTTP 1.1 plain
25+
- APIcast <> HTTP Proxy (camel proxy) <> upstream HTTP 1.1 plain
26+
- APIcast <> HTTP Proxy (env var) <> upstream TLS
27+
- APIcast <> HTTP Proxy (policy) <> upstream TLS
28+
- APIcast <> HTTP Proxy (camel proxy) <> upstream TLS
29+
```
30+
31+
## Why don't we also support disable response buffering?
32+
33+
The response buffering is enabled by default in NGINX (the [`proxy_buffering: on`]() directive). It does
34+
this to shield the backend against slow clients ([slowloris attack](https://www.cloudflare.com/en-au/learning/ddos/ddos-attack-tools/slowloris/)).
35+
36+
If the `proxy_buffering` is disabled, the upstream server will be forced to keep the connection open until all data has been received by the client. Thereforce, NGINX [advises](https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#proxy_buffering-off) against disabling `proxy_buffering` as it will potentially waste upstream server resources.
437

538
## Example configuration
639

740
```
8-
{
9-
"name": "request_unbuffered",
10-
"version": "builtin",
11-
"configuration": {}
12-
}
41+
"policy_chain": [
42+
{
43+
"name": "request_unbuffered",
44+
"version": "builtin",
45+
},
46+
{
47+
"name": "apicast.policy.apicast"
48+
}
49+
]
50+
```
51+
52+
Use with Proxy policy
53+
54+
```
55+
"policy_chain": [
56+
{
57+
"name": "request_unbuffered",
58+
"version": "builtin",
59+
},
60+
{
61+
"name": "apicast.policy.http_proxy",
62+
"configuration": {
63+
"all_proxy": "http://foo:[email protected]:8888/",
64+
"https_proxy": "http://192.168.15.103:8888/",
65+
"http_proxy": "http://192.168.15.103:8888/"
66+
}
67+
}
68+
]
69+
```
70+
71+
Use with Camel Proxy policy
72+
73+
```
74+
"policy_chain": [
75+
{
76+
"name": "request_unbuffered",
77+
"version": "builtin",
78+
},
79+
{
80+
"name": "apicast.policy.camel",
81+
"configuration": {
82+
"http_proxy": "http://192.168.15.103:8080/",
83+
"https_proxy": "http://192.168.15.103:8443/",
84+
"all_proxy": "http://192.168.15.103:8080/"
85+
}
86+
}
87+
]
1388
```
1489

1590
## Caveats
1691

17-
- Because APIcast allows defining mapping rules based on request content, POST requests with
18-
`Content-type: application/x-www-form-urlencoded` will always be buffered regardless of the
92+
- Because APIcast allows defining mapping rules based on request content, ie `POST /some_path?a_param={a_value}`
93+
will match a request like `POST "http://apicast_host:8080/some_path"` with a form URL-encoded body like: `a_param=abc`
94+
, requests with `Content-type: application/x-www-form-urlencoded` will always be buffered regardless of the
1995
`request_unbuffered` policy is enabled or not.
96+
- For a request with "small" body that fits into [`client_body_buffer_size`](https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size) and with header "Transfer-Encoding: chunked", NGINX will always read and know the length of the body.
97+
Then it will send the request to upstream with the "Content-Length" header.
98+
- If a client uses chunked transfer encoding with HTTP/1.0, NGINX will always buffer the request body
99+
- Disable request buffering could potentially expose the backend to [slowloris attack](https://www.cloudflare.com/en-au/learning/ddos/ddos-attack-tools/slowloris/). Therefore, we recommend to only use this policy when needed.

0 commit comments

Comments
 (0)