文档
一个 项目

request_body

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

语法

request_body [<匹配器>] {
	max_size <值>
	set <主体内容>
}
  • 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
		}
	}
}