@marcel91200 / caddy Mirror · read-only / commits / b6609937
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

reverseproxy: Add max_idle_conns_per_host; fix godocs (#3829)

Francis Lavoie committed Oct 30, 2020 at 14:05 UTC b66099379d065ec3340cbe147f65dcf0a39e8e52
3 files changed +38 -2
caddytest/integration/caddyfile_adapt/reverse_proxy_options.txt renamed
+7 -1
@@ -6,11 +6,15 @@ https://example.com {
6 header_up X-Forwarded-For {remote}
7 header_up X-Forwarded-Port {server_port}
8 header_up X-Forwarded-Proto "http"
9 +
10 + buffer_requests
11 +
12 transport http {
13 versions h2c 2
14 compression off
15 + max_conns_per_host 5
16 + max_idle_conns_per_host 2
17 }
13 - buffer_requests
18 }
19 }
20
@@ -64,6 +68,8 @@ https://example.com {
68 },
69 "transport": {
70 "compression": false,
71 + "max_conns_per_host": 5,
72 + "max_idle_conns_per_host": 2,
73 "protocol": "http",
74 "versions": [
75 "h2c",
modules/caddyhttp/reverseproxy/caddyfile.go
+27 -1
@@ -72,6 +72,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
72 //
73 // # streaming
74 // flush_interval <duration>
75 +// buffer_requests
76 //
77 // # header manipulation
78 // header_up [+|-]<field> [<value|regexp> [<replacement>]]
@@ -588,13 +589,18 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
589 // read_buffer <size>
590 // write_buffer <size>
591 // dial_timeout <duration>
591 -// tls_client_auth <cert_file> <key_file>
592 +// tls
593 +// tls_client_auth <automate_name> | <cert_file> <key_file>
594 // tls_insecure_skip_verify
595 // tls_timeout <duration>
596 // tls_trusted_ca_certs <cert_files...>
597 +// tls_server_name <sni>
598 // keepalive [off|<duration>]
599 // keepalive_idle_conns <max_count>
600 // versions <versions...>
601 +// compression off
602 +// max_conns_per_host <count>
603 +// max_idle_conns_per_host <count>
604 // }
605 //
606 func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
@@ -738,6 +744,26 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
744 }
745 }
746
747 + case "max_conns_per_host":
748 + if !d.NextArg() {
749 + return d.ArgErr()
750 + }
751 + num, err := strconv.Atoi(d.Val())
752 + if err != nil {
753 + return d.Errf("bad integer value '%s': %v", d.Val(), err)
754 + }
755 + h.MaxConnsPerHost = num
756 +
757 + case "max_idle_conns_per_host":
758 + if !d.NextArg() {
759 + return d.ArgErr()
760 + }
761 + num, err := strconv.Atoi(d.Val())
762 + if err != nil {
763 + return d.Errf("bad integer value '%s': %v", d.Val(), err)
764 + }
765 + h.MaxIdleConnsPerHost = num
766 +
767 default:
768 return d.Errf("unrecognized subdirective %s", d.Val())
769 }
modules/caddyhttp/reverseproxy/httptransport.go
+4
@@ -62,6 +62,9 @@ type HTTPTransport struct {
62 // Maximum number of connections per host. Default: 0 (no limit)
63 MaxConnsPerHost int `json:"max_conns_per_host,omitempty"`
64
65 + // Maximum number of idle connections per host. Default: 0 (uses Go's default of 2)
66 + MaxIdleConnsPerHost int `json:"max_idle_conns_per_host,omitempty"`
67 +
68 // How long to wait before timing out trying to connect to
69 // an upstream.
70 DialTimeout caddy.Duration `json:"dial_timeout,omitempty"`
@@ -193,6 +196,7 @@ func (h *HTTPTransport) NewTransport(ctx caddy.Context) (*http.Transport, error)
196 return conn, nil
197 },
198 MaxConnsPerHost: h.MaxConnsPerHost,
199 + MaxIdleConnsPerHost: h.MaxIdleConnsPerHost,
200 ResponseHeaderTimeout: time.Duration(h.ResponseHeaderTimeout),
201 ExpectContinueTimeout: time.Duration(h.ExpectContinueTimeout),
202 MaxResponseHeaderBytes: h.MaxResponseHeaderSize,