From 78b4adfac6996020f651b400fdd506f0b79c6015 Mon Sep 17 00:00:00 2001 From: Steffen Busch <37350514+steffenbusch@users.noreply.github.com> Date: Sun, 27 Apr 2025 11:50:46 +0200 Subject: [PATCH] Add documentation for the `set` option in `request_body` directive (#468) --- .../caddyfile/directives/request_body.md | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/docs/markdown/caddyfile/directives/request_body.md b/src/docs/markdown/caddyfile/directives/request_body.md index 3dfbf3e..e25cd26 100644 --- a/src/docs/markdown/caddyfile/directives/request_body.md +++ b/src/docs/markdown/caddyfile/directives/request_body.md @@ -6,17 +6,19 @@ title: request_body (Caddyfile directive) Manipulates or sets restrictions on the bodies of incoming requests. - ## Syntax ```caddy-d request_body [] { max_size + set } ``` - **max_size** is the maximum size in bytes allowed for the request body. It accepts all size values supported by [go-humanize](https://pkg.go.dev/github.com/dustin/go-humanize#pkg-constants). Reads of more bytes will return an error with HTTP status `413`. +⚠️ Experimental | v2.10.0+ +- **set** allows setting the request body to specific content. The content can include placeholders to dynamically insert data. ## Examples @@ -30,3 +32,21 @@ example.com { reverse_proxy localhost:8080 } ``` + +Set the request body with a JSON structure containing a SQL query: + +```caddy +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 + } + } +} +```