You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-11-27 22:38:39 +02:00
feat: allow disable-keep-alives configuration in upstream (#3156)
Signed-off-by: Jan Larwig <jan@larwig.com>
This commit is contained in:
@@ -31,10 +31,11 @@ type LegacyOptions struct {
|
||||
func NewLegacyOptions() *LegacyOptions {
|
||||
return &LegacyOptions{
|
||||
LegacyUpstreams: LegacyUpstreams{
|
||||
PassHostHeader: true,
|
||||
ProxyWebSockets: true,
|
||||
FlushInterval: DefaultUpstreamFlushInterval,
|
||||
Timeout: DefaultUpstreamTimeout,
|
||||
PassHostHeader: true,
|
||||
ProxyWebSockets: true,
|
||||
FlushInterval: DefaultUpstreamFlushInterval,
|
||||
Timeout: DefaultUpstreamTimeout,
|
||||
DisableKeepAlives: false,
|
||||
},
|
||||
|
||||
LegacyHeaders: LegacyHeaders{
|
||||
@@ -105,6 +106,7 @@ type LegacyUpstreams struct {
|
||||
SSLUpstreamInsecureSkipVerify bool `flag:"ssl-upstream-insecure-skip-verify" cfg:"ssl_upstream_insecure_skip_verify"`
|
||||
Upstreams []string `flag:"upstream" cfg:"upstreams"`
|
||||
Timeout time.Duration `flag:"upstream-timeout" cfg:"upstream_timeout"`
|
||||
DisableKeepAlives bool `flag:"disable-keep-alives" cfg:"disable_keep_alives"`
|
||||
}
|
||||
|
||||
func legacyUpstreamsFlagSet() *pflag.FlagSet {
|
||||
@@ -116,6 +118,7 @@ func legacyUpstreamsFlagSet() *pflag.FlagSet {
|
||||
flagSet.Bool("ssl-upstream-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS upstreams")
|
||||
flagSet.StringSlice("upstream", []string{}, "the http url(s) of the upstream endpoint, file:// paths for static files or static://<status_code> for static response. Routing is based on the path")
|
||||
flagSet.Duration("upstream-timeout", DefaultUpstreamTimeout, "maximum amount of time the server will wait for a response from the upstream")
|
||||
flagSet.Bool("disable-keep-alives", false, "disable HTTP keep-alive connections to the upstream server")
|
||||
|
||||
return flagSet
|
||||
}
|
||||
@@ -144,6 +147,7 @@ func (l *LegacyUpstreams) convert() (UpstreamConfig, error) {
|
||||
ProxyWebSockets: &l.ProxyWebSockets,
|
||||
FlushInterval: &flushInterval,
|
||||
Timeout: &timeout,
|
||||
DisableKeepAlives: l.DisableKeepAlives,
|
||||
}
|
||||
|
||||
switch u.Scheme {
|
||||
@@ -176,6 +180,7 @@ func (l *LegacyUpstreams) convert() (UpstreamConfig, error) {
|
||||
upstream.ProxyWebSockets = nil
|
||||
upstream.FlushInterval = nil
|
||||
upstream.Timeout = nil
|
||||
upstream.DisableKeepAlives = false
|
||||
case "unix":
|
||||
upstream.Path = "/"
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
legacyOpts.LegacyUpstreams.SSLUpstreamInsecureSkipVerify = true
|
||||
legacyOpts.LegacyUpstreams.Upstreams = []string{"http://foo.bar/baz", "file:///var/lib/website#/bar", "static://204"}
|
||||
legacyOpts.LegacyProvider.ClientID = "oauth-proxy"
|
||||
legacyOpts.LegacyUpstreams.DisableKeepAlives = false
|
||||
|
||||
truth := true
|
||||
staticCode := 204
|
||||
@@ -38,6 +39,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
PassHostHeader: &truth,
|
||||
ProxyWebSockets: &truth,
|
||||
Timeout: &timeout,
|
||||
DisableKeepAlives: legacyOpts.LegacyUpstreams.DisableKeepAlives,
|
||||
},
|
||||
{
|
||||
ID: "/bar",
|
||||
@@ -48,6 +50,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
PassHostHeader: &truth,
|
||||
ProxyWebSockets: &truth,
|
||||
Timeout: &timeout,
|
||||
DisableKeepAlives: legacyOpts.LegacyUpstreams.DisableKeepAlives,
|
||||
},
|
||||
{
|
||||
ID: "static://204",
|
||||
@@ -60,6 +63,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
PassHostHeader: nil,
|
||||
ProxyWebSockets: nil,
|
||||
Timeout: nil,
|
||||
DisableKeepAlives: legacyOpts.LegacyUpstreams.DisableKeepAlives,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -145,6 +149,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
proxyWebSockets := true
|
||||
flushInterval := Duration(5 * time.Second)
|
||||
timeout := Duration(5 * time.Second)
|
||||
disableKeepAlives := true
|
||||
|
||||
// Test cases and expected outcomes
|
||||
validHTTP := "http://foo.bar/baz"
|
||||
@@ -157,6 +162,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
ProxyWebSockets: &proxyWebSockets,
|
||||
FlushInterval: &flushInterval,
|
||||
Timeout: &timeout,
|
||||
DisableKeepAlives: disableKeepAlives,
|
||||
}
|
||||
|
||||
// Test cases and expected outcomes
|
||||
@@ -170,6 +176,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
ProxyWebSockets: &proxyWebSockets,
|
||||
FlushInterval: &flushInterval,
|
||||
Timeout: &timeout,
|
||||
DisableKeepAlives: disableKeepAlives,
|
||||
}
|
||||
|
||||
validFileWithFragment := "file:///var/lib/website#/bar"
|
||||
@@ -182,6 +189,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
ProxyWebSockets: &proxyWebSockets,
|
||||
FlushInterval: &flushInterval,
|
||||
Timeout: &timeout,
|
||||
DisableKeepAlives: disableKeepAlives,
|
||||
}
|
||||
|
||||
validStatic := "static://204"
|
||||
@@ -197,6 +205,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
ProxyWebSockets: nil,
|
||||
FlushInterval: nil,
|
||||
Timeout: nil,
|
||||
DisableKeepAlives: false,
|
||||
}
|
||||
|
||||
invalidStatic := "static://abc"
|
||||
@@ -212,6 +221,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
ProxyWebSockets: nil,
|
||||
FlushInterval: nil,
|
||||
Timeout: nil,
|
||||
DisableKeepAlives: false,
|
||||
}
|
||||
|
||||
invalidHTTP := ":foo"
|
||||
@@ -226,6 +236,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
ProxyWebSockets: proxyWebSockets,
|
||||
FlushInterval: time.Duration(flushInterval),
|
||||
Timeout: time.Duration(timeout),
|
||||
DisableKeepAlives: disableKeepAlives,
|
||||
}
|
||||
|
||||
upstreams, err := legacyUpstreams.convert()
|
||||
|
||||
@@ -93,4 +93,8 @@ type Upstream struct {
|
||||
// Timeout is the maximum duration the server will wait for a response from the upstream server.
|
||||
// Defaults to 30 seconds.
|
||||
Timeout *Duration `json:"timeout,omitempty"`
|
||||
|
||||
// DisableKeepAlives disables HTTP keep-alive connections to the upstream server.
|
||||
// Defaults to false.
|
||||
DisableKeepAlives bool `json:"disableKeepAlives,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user