git.iko.soy/typeable/oauth2-proxy
on master help sign in
Add DefaultUpstreamFlushInterval to replace magic time.Second value
commitaed43a54da328b3f4d85660598818f79c82bcaa3 authorJoel Speed <joel.speed@hotmail.co.uk> dateThu 19 Nov 2020, 10:35 (6 years ago) parent8e582ac
4 files changed+11−6
pkg/apis/options/legacy_options.go+2−2 pkg/apis/options/upstreams.go+7 pkg/upstream/http.go+1−2 pkg/validation/upstreams.go+1−2
pkg/apis/options/legacy_options.go+2−2
@@ -27,7 +27,7 @@ func NewLegacyOptions() *LegacyOptions {
2727 LegacyUpstreams: LegacyUpstreams{
2828 PassHostHeader: true,
2929 ProxyWebSockets: true,
30− FlushInterval: time.Duration(1) * time.Second,
30+ FlushInterval: DefaultUpstreamFlushInterval,
3131 },
3232
3333 LegacyHeaders: LegacyHeaders{
@@ -62,7 +62,7 @@ type LegacyUpstreams struct {
6262func legacyUpstreamsFlagSet() *pflag.FlagSet {
6363 flagSet := pflag.NewFlagSet("upstreams", pflag.ExitOnError)
6464
65− flagSet.Duration("flush-interval", time.Duration(1)*time.Second, "period between response flushing when streaming responses")
65+ flagSet.Duration("flush-interval", DefaultUpstreamFlushInterval, "period between response flushing when streaming responses")
6666 flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream")
6767 flagSet.Bool("proxy-websockets", true, "enables WebSocket proxying")
6868 flagSet.Bool("ssl-upstream-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS upstreams")
pkg/apis/options/upstreams.go+7
@@ -1,5 +1,12 @@
11package options
22
3+import "time"
4+
5+const (
6+ // DefaultUpstreamFlushInterval is the default value for the Upstream FlushInterval.
7+ DefaultUpstreamFlushInterval = 1 * time.Second
8+)
9+
310// Upstreams is a collection of definitions for upstream servers.
411type Upstreams []Upstream
512
pkg/upstream/http.go+1−2
@@ -6,7 +6,6 @@ import (
66 "net/http/httputil"
77 "net/url"
88 "strings"
9− "time"
109
1110 "github.com/mbland/hmacauth"
1211 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
@@ -100,7 +99,7 @@ func newReverseProxy(target *url.URL, upstream options.Upstream, errorHandler Pr
10099 if upstream.FlushInterval != nil {
101100 proxy.FlushInterval = upstream.FlushInterval.Duration()
102101 } else {
103− proxy.FlushInterval = 1 * time.Second
102+ proxy.FlushInterval = options.DefaultUpstreamFlushInterval
104103 }
105104
106105 // InsecureSkipVerify is a configurable option we allow
pkg/validation/upstreams.go+1−2
@@ -3,7 +3,6 @@ package validation
33import (
44 "fmt"
55 "net/url"
6− "time"
76
87 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
98)
@@ -70,7 +69,7 @@ func validateStaticUpstream(upstream options.Upstream) []string {
7069 if upstream.InsecureSkipTLSVerify {
7170 msgs = append(msgs, fmt.Sprintf("upstream %q has insecureSkipTLSVerify, but is a static upstream, this will have no effect.", upstream.ID))
7271 }
73− if upstream.FlushInterval != nil && upstream.FlushInterval.Duration() != time.Second {
72+ if upstream.FlushInterval != nil && upstream.FlushInterval.Duration() != options.DefaultUpstreamFlushInterval {
7473 msgs = append(msgs, fmt.Sprintf("upstream %q has flushInterval, but is a static upstream, this will have no effect.", upstream.ID))
7574 }
7675 if upstream.PassHostHeader != nil {