config: allow specifying auto codec type in all-in-one mode (#2846)

* config: allow specifying auto codec type in all-in-one mode

* fix test

* fix test
This commit is contained in:
Caleb Doxsey 2021-12-22 12:34:58 -07:00 committed by GitHub
parent 0ee6a72c02
commit 6b949a5c2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 10 deletions

View file

@ -15,6 +15,7 @@ type CodecType string
// CodecTypes
const (
CodecTypeUnset CodecType = ""
CodecTypeAuto CodecType = "auto"
CodecTypeHTTP1 CodecType = "http1"
CodecTypeHTTP2 CodecType = "http2"

17
config/codec_type_test.go Normal file
View file

@ -0,0 +1,17 @@
package config
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOptions_GetCodecType(t *testing.T) {
options := NewDefaultOptions()
assert.Equal(t, CodecTypeHTTP1, options.GetCodecType())
options.Services = "proxy"
assert.Equal(t, CodecTypeAuto, options.GetCodecType())
options.Services = "all"
options.CodecType = CodecTypeAuto
assert.Equal(t, CodecTypeAuto, options.GetCodecType())
}

View file

@ -312,7 +312,6 @@ var defaultOptions = Options{
Services: "all",
CookieHTTPOnly: true,
CookieSecure: true,
CodecType: CodecTypeAuto,
CookieExpire: 14 * time.Hour,
CookieName: "_pomerium",
DefaultUpstreamTimeout: 30 * time.Second,
@ -1034,8 +1033,11 @@ func (o *Options) GetQPS() float64 {
// GetCodecType gets a codec type.
func (o *Options) GetCodecType() CodecType {
if IsAll(o.Services) && o.CodecType == CodecTypeAuto {
return CodecTypeHTTP1
if o.CodecType == CodecTypeUnset {
if IsAll(o.Services) {
return CodecTypeHTTP1
}
return CodecTypeAuto
}
return o.CodecType
}

View file

@ -313,7 +313,6 @@ func TestOptionsFromViper(t *testing.T) {
EnvoyAdminAccessLogPath: os.DevNull,
EnvoyAdminProfilePath: os.DevNull,
EnvoyAdminAddress: "127.0.0.1:9901",
CodecType: CodecTypeAuto,
},
false,
},
@ -335,7 +334,6 @@ func TestOptionsFromViper(t *testing.T) {
EnvoyAdminAccessLogPath: os.DevNull,
EnvoyAdminProfilePath: os.DevNull,
EnvoyAdminAddress: "127.0.0.1:9901",
CodecType: CodecTypeAuto,
},
false,
},
@ -693,8 +691,3 @@ func mustParseWeightedURLs(t *testing.T, urls ...string) []WeightedURL {
require.NoError(t, err)
return wu
}
func TestDefaults(t *testing.T) {
o := NewDefaultOptions()
assert.Equal(t, CodecTypeAuto, o.CodecType)
}