-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: spacewander <[email protected]>
- Loading branch information
1 parent
1519036
commit c6cfd61
Showing
3 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: Buffer | ||
--- | ||
|
||
## Description | ||
|
||
The `buffer` plugin fully buffers the complete request, by leveraging Envoy's `buffer` filter. It can be used for several purposes, like: | ||
|
||
* Protecting applications from high network latency. | ||
* Some plugins will buffer the whole request, which may trigger a 413 HTTP status code when the max request body size is met. We can set the `maxRequestBytes` larger than `per_connection_buffer_limit_bytes` to increase the max request body size per route. | ||
|
||
## Attribute | ||
|
||
| | | | ||
|-------|---------| | ||
| Type | General | | ||
| Order | Outer | | ||
|
||
## Configuration | ||
|
||
| Name | Type | Required | Validation | Description | | ||
|-----------------|--------|----------|------------|--------------------------------------------------------------------------------------------| | ||
| maxRequestBytes | uint32 | True | | The maximum request body size that the filter will buffer before returning a 413 response. | | ||
|
||
## Usage | ||
|
||
Assumed we have the HTTPRoute below attached to `localhost:10000`, and a backend server listening to port `8080`: | ||
|
||
```yaml | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: default | ||
spec: | ||
parentRefs: | ||
- name: default | ||
namespace: default | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: / | ||
backendRefs: | ||
- name: backend | ||
port: 8080 | ||
``` | ||
By applying the configuration below, the request to `http://localhost:10000/` is buffered until the body length meets the max requests bytes 4: | ||
|
||
```yaml | ||
apiVersion: mosn.io/v1 | ||
kind: HTTPFilterPolicy | ||
metadata: | ||
name: policy | ||
spec: | ||
targetRef: | ||
group: gateway.networking.k8s.io | ||
kind: HTTPRoute | ||
name: default | ||
filters: | ||
buffer: | ||
config: | ||
maxRequestBytes: 4 | ||
``` | ||
|
||
We can test it out: | ||
|
||
``` | ||
$ curl -d "hello" http://localhost:10000/ -i | ||
HTTP/1.1 413 Payload Too Large | ||
``` | ||
|
||
``` | ||
$ curl -d "hell" http://localhost:10000/ -i | ||
HTTP/1.1 200 OK | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
title: Buffer | ||
--- | ||
|
||
## 说明 | ||
|
||
`buffer` 插件通过利用 Envoy 的 `buffer` 过滤器完全缓冲整个请求。它可以用于几个目的,比如: | ||
|
||
* 保护应用程序免受高网络延迟的影响。 | ||
* 一些插件会缓冲整个请求。当请求体超过最大长度时,将触发 413 HTTP 状态码。我们可以设置 `maxRequestBytes` 大于 `per_connection_buffer_limit_bytes` 来增加单个路由的最大请求体大小。 | ||
|
||
## 属性 | ||
| | | | ||
|-------|---------| | ||
| Type | General | | ||
| Order | Outer | | ||
|
||
## 配置 | ||
|
||
| 名称 | 类型 | 必选 | 校验规则 | 说明 | | ||
|-----------------|--------|------|----------|-------------------------------------------------------------------------------------| | ||
| maxRequestBytes | uint32 | 是 | | 缓冲的请求体最大大小,超过此大小将返回 413 响应。 | | ||
|
||
## 用法 | ||
|
||
假设我们有下面附加到 `localhost:10000` 的 HTTPRoute,并且有一个后端服务器监听端口 `8080`: | ||
|
||
```yaml | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: default | ||
spec: | ||
parentRefs: | ||
- name: default | ||
namespace: default | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: / | ||
backendRefs: | ||
- name: backend | ||
port: 8080 | ||
``` | ||
通过应用下面的配置,发送到 `http://localhost:10000/` 的请求会被缓冲,直到请求体长度达到最大请求字节数 4: | ||
|
||
```yaml | ||
apiVersion: mosn.io/v1 | ||
kind: HTTPFilterPolicy | ||
metadata: | ||
name: policy | ||
spec: | ||
targetRef: | ||
group: gateway.networking.k8s.io | ||
kind: HTTPRoute | ||
name: default | ||
filters: | ||
buffer: | ||
config: | ||
maxRequestBytes: 4 | ||
``` | ||
|
||
我们可以测试一下: | ||
|
||
``` | ||
$ curl -d "hello" http://localhost:10000/ -i | ||
HTTP/1.1 413 Payload Too Large | ||
``` | ||
``` | ||
$ curl -d "hell" http://localhost:10000/ -i | ||
HTTP/1.1 200 OK | ||
``` |