Add DefaultUpstreamFlushInterval to replace magic time.Second value
This commit is contained in:
		
							parent
							
								
									8e582ac02a
								
							
						
					
					
						commit
						aed43a54da
					
				|  | @ -27,7 +27,7 @@ func NewLegacyOptions() *LegacyOptions { | ||||||
| 		LegacyUpstreams: LegacyUpstreams{ | 		LegacyUpstreams: LegacyUpstreams{ | ||||||
| 			PassHostHeader:  true, | 			PassHostHeader:  true, | ||||||
| 			ProxyWebSockets: true, | 			ProxyWebSockets: true, | ||||||
| 			FlushInterval:   time.Duration(1) * time.Second, | 			FlushInterval:   DefaultUpstreamFlushInterval, | ||||||
| 		}, | 		}, | ||||||
| 
 | 
 | ||||||
| 		LegacyHeaders: LegacyHeaders{ | 		LegacyHeaders: LegacyHeaders{ | ||||||
|  | @ -62,7 +62,7 @@ type LegacyUpstreams struct { | ||||||
| func legacyUpstreamsFlagSet() *pflag.FlagSet { | func legacyUpstreamsFlagSet() *pflag.FlagSet { | ||||||
| 	flagSet := pflag.NewFlagSet("upstreams", pflag.ExitOnError) | 	flagSet := pflag.NewFlagSet("upstreams", pflag.ExitOnError) | ||||||
| 
 | 
 | ||||||
| 	flagSet.Duration("flush-interval", time.Duration(1)*time.Second, "period between response flushing when streaming responses") | 	flagSet.Duration("flush-interval", DefaultUpstreamFlushInterval, "period between response flushing when streaming responses") | ||||||
| 	flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream") | 	flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream") | ||||||
| 	flagSet.Bool("proxy-websockets", true, "enables WebSocket proxying") | 	flagSet.Bool("proxy-websockets", true, "enables WebSocket proxying") | ||||||
| 	flagSet.Bool("ssl-upstream-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS upstreams") | 	flagSet.Bool("ssl-upstream-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS upstreams") | ||||||
|  |  | ||||||
|  | @ -1,5 +1,12 @@ | ||||||
| package options | package options | ||||||
| 
 | 
 | ||||||
|  | import "time" | ||||||
|  | 
 | ||||||
|  | const ( | ||||||
|  | 	// DefaultUpstreamFlushInterval is the default value for the Upstream FlushInterval.
 | ||||||
|  | 	DefaultUpstreamFlushInterval = 1 * time.Second | ||||||
|  | ) | ||||||
|  | 
 | ||||||
| // Upstreams is a collection of definitions for upstream servers.
 | // Upstreams is a collection of definitions for upstream servers.
 | ||||||
| type Upstreams []Upstream | type Upstreams []Upstream | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,7 +6,6 @@ import ( | ||||||
| 	"net/http/httputil" | 	"net/http/httputil" | ||||||
| 	"net/url" | 	"net/url" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/mbland/hmacauth" | 	"github.com/mbland/hmacauth" | ||||||
| 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | ||||||
|  | @ -100,7 +99,7 @@ func newReverseProxy(target *url.URL, upstream options.Upstream, errorHandler Pr | ||||||
| 	if upstream.FlushInterval != nil { | 	if upstream.FlushInterval != nil { | ||||||
| 		proxy.FlushInterval = upstream.FlushInterval.Duration() | 		proxy.FlushInterval = upstream.FlushInterval.Duration() | ||||||
| 	} else { | 	} else { | ||||||
| 		proxy.FlushInterval = 1 * time.Second | 		proxy.FlushInterval = options.DefaultUpstreamFlushInterval | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// InsecureSkipVerify is a configurable option we allow
 | 	// InsecureSkipVerify is a configurable option we allow
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ package validation | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/url" | 	"net/url" | ||||||
| 	"time" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | ||||||
| ) | ) | ||||||
|  | @ -70,7 +69,7 @@ func validateStaticUpstream(upstream options.Upstream) []string { | ||||||
| 	if upstream.InsecureSkipTLSVerify { | 	if upstream.InsecureSkipTLSVerify { | ||||||
| 		msgs = append(msgs, fmt.Sprintf("upstream %q has insecureSkipTLSVerify, but is a static upstream, this will have no effect.", upstream.ID)) | 		msgs = append(msgs, fmt.Sprintf("upstream %q has insecureSkipTLSVerify, but is a static upstream, this will have no effect.", upstream.ID)) | ||||||
| 	} | 	} | ||||||
| 	if upstream.FlushInterval != nil && upstream.FlushInterval.Duration() != time.Second { | 	if upstream.FlushInterval != nil && upstream.FlushInterval.Duration() != options.DefaultUpstreamFlushInterval { | ||||||
| 		msgs = append(msgs, fmt.Sprintf("upstream %q has flushInterval, but is a static upstream, this will have no effect.", upstream.ID)) | 		msgs = append(msgs, fmt.Sprintf("upstream %q has flushInterval, but is a static upstream, this will have no effect.", upstream.ID)) | ||||||
| 	} | 	} | ||||||
| 	if upstream.PassHostHeader != nil { | 	if upstream.PassHostHeader != nil { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue