From 860cc6adfe6a5022baf5fd387e0d10c5e3a174fe Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 2 Nov 2020 16:59:02 -0500 Subject: [PATCH] reverseproxy: Wire up some http transport options in Caddyfile (#3843) --- .../caddyfile_adapt/reverse_proxy_options.txt | 17 ++++++- modules/caddyhttp/reverseproxy/caddyfile.go | 50 +++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/caddytest/integration/caddyfile_adapt/reverse_proxy_options.txt b/caddytest/integration/caddyfile_adapt/reverse_proxy_options.txt index 423bd8fd..f9b0010a 100644 --- a/caddytest/integration/caddyfile_adapt/reverse_proxy_options.txt +++ b/caddytest/integration/caddyfile_adapt/reverse_proxy_options.txt @@ -10,6 +10,14 @@ https://example.com { buffer_requests transport http { + read_buffer 10MB + write_buffer 20MB + max_response_header 30MB + dial_timeout 3s + dial_fallback_delay 5s + response_header_timeout 8s + expect_continue_timeout 9s + versions h2c 2 compression off max_conns_per_host 5 @@ -68,13 +76,20 @@ https://example.com { }, "transport": { "compression": false, + "dial_fallback_delay": 5000000000, + "dial_timeout": 3000000000, + "expect_continue_timeout": 9000000000, "max_conns_per_host": 5, "max_idle_conns_per_host": 2, + "max_response_header_size": 30000000, "protocol": "http", + "read_buffer_size": 10000000, + "response_header_timeout": 8000000000, "versions": [ "h2c", "2" - ] + ], + "write_buffer_size": 20000000 }, "upstreams": [ { diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go index 7fa118c2..c5f8e17e 100644 --- a/modules/caddyhttp/reverseproxy/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/caddyfile.go @@ -586,9 +586,13 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { // UnmarshalCaddyfile deserializes Caddyfile tokens into h. // // transport http { -// read_buffer -// write_buffer -// dial_timeout +// read_buffer +// write_buffer +// max_response_header +// dial_timeout +// dial_fallback_delay +// response_header_timeout +// expect_continue_timeout // tls // tls_client_auth | // tls_insecure_skip_verify @@ -627,6 +631,16 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { } h.WriteBufferSize = int(size) + case "max_response_header": + if !d.NextArg() { + return d.ArgErr() + } + size, err := humanize.ParseBytes(d.Val()) + if err != nil { + return d.Errf("invalid max response header size '%s': %v", d.Val(), err) + } + h.MaxResponseHeaderSize = int64(size) + case "dial_timeout": if !d.NextArg() { return d.ArgErr() @@ -637,6 +651,36 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { } h.DialTimeout = caddy.Duration(dur) + case "dial_fallback_delay": + if !d.NextArg() { + return d.ArgErr() + } + dur, err := caddy.ParseDuration(d.Val()) + if err != nil { + return d.Errf("bad fallback delay value '%s': %v", d.Val(), err) + } + h.FallbackDelay = caddy.Duration(dur) + + case "response_header_timeout": + if !d.NextArg() { + return d.ArgErr() + } + dur, err := caddy.ParseDuration(d.Val()) + if err != nil { + return d.Errf("bad timeout value '%s': %v", d.Val(), err) + } + h.ResponseHeaderTimeout = caddy.Duration(dur) + + case "expect_continue_timeout": + if !d.NextArg() { + return d.ArgErr() + } + dur, err := caddy.ParseDuration(d.Val()) + if err != nil { + return d.Errf("bad timeout value '%s': %v", d.Val(), err) + } + h.ExpectContinueTimeout = caddy.Duration(dur) + case "tls_client_auth": if h.TLS == nil { h.TLS = new(TLSConfig)