mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-14 14:56:27 +03:00
reverseproxy: Add max_idle_conns_per_host; fix godocs (#3829)
This commit is contained in:
parent
c9fdff9976
commit
b66099379d
3 changed files with 38 additions and 2 deletions
|
@ -6,11 +6,15 @@ https://example.com {
|
||||||
header_up X-Forwarded-For {remote}
|
header_up X-Forwarded-For {remote}
|
||||||
header_up X-Forwarded-Port {server_port}
|
header_up X-Forwarded-Port {server_port}
|
||||||
header_up X-Forwarded-Proto "http"
|
header_up X-Forwarded-Proto "http"
|
||||||
|
|
||||||
|
buffer_requests
|
||||||
|
|
||||||
transport http {
|
transport http {
|
||||||
versions h2c 2
|
versions h2c 2
|
||||||
compression off
|
compression off
|
||||||
|
max_conns_per_host 5
|
||||||
|
max_idle_conns_per_host 2
|
||||||
}
|
}
|
||||||
buffer_requests
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +68,8 @@ https://example.com {
|
||||||
},
|
},
|
||||||
"transport": {
|
"transport": {
|
||||||
"compression": false,
|
"compression": false,
|
||||||
|
"max_conns_per_host": 5,
|
||||||
|
"max_idle_conns_per_host": 2,
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"versions": [
|
"versions": [
|
||||||
"h2c",
|
"h2c",
|
|
@ -72,6 +72,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
|
||||||
//
|
//
|
||||||
// # streaming
|
// # streaming
|
||||||
// flush_interval <duration>
|
// flush_interval <duration>
|
||||||
|
// buffer_requests
|
||||||
//
|
//
|
||||||
// # header manipulation
|
// # header manipulation
|
||||||
// header_up [+|-]<field> [<value|regexp> [<replacement>]]
|
// header_up [+|-]<field> [<value|regexp> [<replacement>]]
|
||||||
|
@ -588,13 +589,18 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
// read_buffer <size>
|
// read_buffer <size>
|
||||||
// write_buffer <size>
|
// write_buffer <size>
|
||||||
// dial_timeout <duration>
|
// dial_timeout <duration>
|
||||||
// tls_client_auth <cert_file> <key_file>
|
// tls
|
||||||
|
// tls_client_auth <automate_name> | <cert_file> <key_file>
|
||||||
// tls_insecure_skip_verify
|
// tls_insecure_skip_verify
|
||||||
// tls_timeout <duration>
|
// tls_timeout <duration>
|
||||||
// tls_trusted_ca_certs <cert_files...>
|
// tls_trusted_ca_certs <cert_files...>
|
||||||
|
// tls_server_name <sni>
|
||||||
// keepalive [off|<duration>]
|
// keepalive [off|<duration>]
|
||||||
// keepalive_idle_conns <max_count>
|
// keepalive_idle_conns <max_count>
|
||||||
// versions <versions...>
|
// versions <versions...>
|
||||||
|
// compression off
|
||||||
|
// max_conns_per_host <count>
|
||||||
|
// max_idle_conns_per_host <count>
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
|
@ -738,6 +744,26 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "max_conns_per_host":
|
||||||
|
if !d.NextArg() {
|
||||||
|
return d.ArgErr()
|
||||||
|
}
|
||||||
|
num, err := strconv.Atoi(d.Val())
|
||||||
|
if err != nil {
|
||||||
|
return d.Errf("bad integer value '%s': %v", d.Val(), err)
|
||||||
|
}
|
||||||
|
h.MaxConnsPerHost = num
|
||||||
|
|
||||||
|
case "max_idle_conns_per_host":
|
||||||
|
if !d.NextArg() {
|
||||||
|
return d.ArgErr()
|
||||||
|
}
|
||||||
|
num, err := strconv.Atoi(d.Val())
|
||||||
|
if err != nil {
|
||||||
|
return d.Errf("bad integer value '%s': %v", d.Val(), err)
|
||||||
|
}
|
||||||
|
h.MaxIdleConnsPerHost = num
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return d.Errf("unrecognized subdirective %s", d.Val())
|
return d.Errf("unrecognized subdirective %s", d.Val())
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,9 @@ type HTTPTransport struct {
|
||||||
// Maximum number of connections per host. Default: 0 (no limit)
|
// Maximum number of connections per host. Default: 0 (no limit)
|
||||||
MaxConnsPerHost int `json:"max_conns_per_host,omitempty"`
|
MaxConnsPerHost int `json:"max_conns_per_host,omitempty"`
|
||||||
|
|
||||||
|
// Maximum number of idle connections per host. Default: 0 (uses Go's default of 2)
|
||||||
|
MaxIdleConnsPerHost int `json:"max_idle_conns_per_host,omitempty"`
|
||||||
|
|
||||||
// How long to wait before timing out trying to connect to
|
// How long to wait before timing out trying to connect to
|
||||||
// an upstream.
|
// an upstream.
|
||||||
DialTimeout caddy.Duration `json:"dial_timeout,omitempty"`
|
DialTimeout caddy.Duration `json:"dial_timeout,omitempty"`
|
||||||
|
@ -193,6 +196,7 @@ func (h *HTTPTransport) NewTransport(ctx caddy.Context) (*http.Transport, error)
|
||||||
return conn, nil
|
return conn, nil
|
||||||
},
|
},
|
||||||
MaxConnsPerHost: h.MaxConnsPerHost,
|
MaxConnsPerHost: h.MaxConnsPerHost,
|
||||||
|
MaxIdleConnsPerHost: h.MaxIdleConnsPerHost,
|
||||||
ResponseHeaderTimeout: time.Duration(h.ResponseHeaderTimeout),
|
ResponseHeaderTimeout: time.Duration(h.ResponseHeaderTimeout),
|
||||||
ExpectContinueTimeout: time.Duration(h.ExpectContinueTimeout),
|
ExpectContinueTimeout: time.Duration(h.ExpectContinueTimeout),
|
||||||
MaxResponseHeaderBytes: h.MaxResponseHeaderSize,
|
MaxResponseHeaderBytes: h.MaxResponseHeaderSize,
|
||||||
|
|
Loading…
Reference in a new issue