1. Caddy version (caddy version
):
v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=
2. How I run Caddy:
a. System environment:
Docker, caddy:2-alpine
image
b. Command:
caddy run --config /etc/caddy/caddy_config.json
c. Service/unit/compose file:
N/A
d. My complete Caddyfile or JSON config:
{
"admin": {
"config": {
"persist": false
},
"enforce_origin": false,
"listen": "0.0.0.0:2019",
"origins": []
},
"apps": {
"http": {
"servers": {
"srv0": {
"errors": {
"routes": [
{
"handle": [
{
"error": "Payload Too Large",
"handler": "error",
"status_code": "413"
}
],
"match": [
{
"expression": "{http.request.header.Content-Length} > 15728640"
}
]
}
]
},
"listen": [
":443"
],
"logs": {
"default_logger_name": "log0"
},
"routes": [
{
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "static_response",
"headers": {
"Location": [
"{http.request.uri.query.target}"
]
},
"status_code": 302
}
],
"match": [
{
"path": [
"/site-redirect*"
],
"query": {
"target": [
"*"
]
}
}
]
},
{
"handle": [
{
"handler": "reverse_proxy",
"transport": {
"protocol": "http"
},
"upstreams": [
{
"dial": "localhost:6667"
}
]
}
],
"match": [
{
"path": [
"/api/pub/*",
"/api/gateway/*",
"/auth/oauth/*"
]
}
]
}
]
},
{
"@id": "newroutes",
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "request_body",
"max_size": 15728640
},
{
"handler": "file_server",
"pass_thru": true,
"root": "public"
}
],
"match": [
{
"path_regexp": {
"name": "newroutes_regexp1",
"pattern": "(?i)^/public/*"
}
},
{
"path_regexp": {
"pattern": "(?i)^/(robots|recaptcha|sitemap).*"
}
}
]
},
{
"handle": [
{
"handler": "request_body",
"max_size": 15728640
},
{
"handler": "file_server",
"pass_thru": true,
"root": "v2app"
}
],
"match": [
{
"path_regexp": {
"pattern": "(?i)^/((default|common|polyfills|root_shared|runtime|styles|ng-assets|shared-assets|assets).*)$"
}
}
]
},
{
"handle": [
{
"handler": "request_body",
"max_size": 15728640
},
{
"handler": "rewrite",
"uri": "/{path}"
}
],
"match": [
{
"path_regexp": {
"pattern": "^(?i)(^/$)|((/login|/account-summary).*$)"
}
}
]
},
{
"handle": [
{
"handler": "request_body",
"max_size": 15728640
},
{
"handler": "file_server",
"hide": [
"/etc/caddy/caddy_config.json"
]
}
]
}
]
}
],
"match": [
{
"host": [
"localhost"
]
}
],
"terminal": true
}
],
"tls_connection_policies": [
{
"certificate_selection": {
"any_tag": [
"mycert"
]
}
}
]
}
}
},
"tls": {
"certificates": {
"load_files": [
{
"certificate": "/etc/tls/tls.crt",
"key": "/etc/tls/tls.key",
"tags": [
"mycert"
]
}
]
}
}
},
"logging": {
"logs": {
"default": {
"exclude": [
"http.log.access.log0"
],
"level": "warn"
},
"log0": {
"encoder": {
"format": "json"
},
"include": [
"http.log.access.log0"
],
"level": "info",
"writer": {
"output": "stdout"
}
}
}
}
}
3. The problem I’m having:
I want to put a max_size on any request body and want Caddy to respond with an HTTP 413 code (like a web server should), but I noticed that the code for max_size of the request body handler only limits the body size for the next handler. There isn’t any documentation on how to mimic servers such as nginx or apache where the max body size is setting where they generate a 413.
4. Error messages and/or full log output:
Oddly, no amount of artificially generating large requests will generate an HTTP 413 error. If I use Postman to add a 30MB file into a post playload to the login page, the login page happily responds with a HTTP 200 which is not what I would expect. Are there examples somewhere online of using the errors
block to capture when the max_size of a request has exceeded the set number of bytes and intercept the response back to the client?
5. What I already tried:
I have tried to tinker with the configuration above, but nothing about Caddy’s behavior changes.