From 59026d762ac0ed3882d83da06db068a299ce4f09 Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Wed, 20 Sep 2023 19:48:25 +0100 Subject: [PATCH] reverseproxy: fix parsing fails for unlimited request/response buffers Signed-off-by: Fred Cox --- .../caddyfile_adapt/reverse_proxy_buffers.txt | 58 +++++++++++++++++++ modules/caddyhttp/reverseproxy/caddyfile.go | 17 ++++-- 2 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 caddytest/integration/caddyfile_adapt/reverse_proxy_buffers.txt diff --git a/caddytest/integration/caddyfile_adapt/reverse_proxy_buffers.txt b/caddytest/integration/caddyfile_adapt/reverse_proxy_buffers.txt new file mode 100644 index 000000000000..317899470e7c --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/reverse_proxy_buffers.txt @@ -0,0 +1,58 @@ +https://example.com { + reverse_proxy https://localhost:54321 { + request_buffers unlimited + response_buffers unlimited + } +} + +---------- +{ + "apps": { + "http": { + "servers": { + "srv0": { + "listen": [ + ":443" + ], + "routes": [ + { + "match": [ + { + "host": [ + "example.com" + ] + } + ], + "handle": [ + { + "handler": "subroute", + "routes": [ + { + "handle": [ + { + "handler": "reverse_proxy", + "request_buffers": -1, + "response_buffers": -1, + "transport": { + "protocol": "http", + "tls": {} + }, + "upstreams": [ + { + "dial": "localhost:54321" + } + ] + } + ] + } + ] + } + ], + "terminal": true + } + ] + } + } + } + } +} diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go index 674776f87a83..533a82eba12f 100644 --- a/modules/caddyhttp/reverseproxy/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/caddyfile.go @@ -551,17 +551,24 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { if !d.NextArg() { return d.ArgErr() } - size, err := humanize.ParseBytes(d.Val()) - if err != nil { - return d.Errf("invalid byte size '%s': %v", d.Val(), err) + val := d.Val() + var size int64 + if val == "unlimited" { + size = -1 + } else { + usize, err := humanize.ParseBytes(val) + if err != nil { + return d.Errf("invalid byte size '%s': %v", val, err) + } + size = int64(usize) } if d.NextArg() { return d.ArgErr() } if subdir == "request_buffers" { - h.RequestBuffers = int64(size) + h.RequestBuffers = size } else if subdir == "response_buffers" { - h.ResponseBuffers = int64(size) + h.ResponseBuffers = size } // TODO: These three properties are deprecated; remove them sometime after v2.6.4