文档
一个 项目

request_body

操作或设置对传入请求主体的限制。

语法

request_body [<matcher>] {
	max_size <value>
	set <body_content>
}
  • max_size 是请求主体允许的最大字节数。它接受由 go-humanize 支持的所有大小值。读取更多字节将返回 HTTP 状态码为 413 的错误。

⚠️ 实验性 | v2.10.0+

  • set 允许将请求主体设置为特定内容。内容可以包含占位符以动态插入数据。

示例

将请求主体大小限制为 10 兆字节:

example.com {
	request_body {
		max_size 10MB
	}
	reverse_proxy localhost:8080
}

将请求主体设置为包含 SQL 查询的 JSON 结构:

example.com {
	handle /jazz {
		request_body {
			set `\{"statementText":"SELECT name, genre, debut_year FROM artists WHERE genre = 'Jazz'"}`
		}

		reverse_proxy localhost:8080 {
			header_up Content-Type application/json
			method POST
			rewrite * /execute-sql
		}
	}
}