added proxy-http-version annotation to override the HTTP/1.1 default connection type to reverse proxy backends

This commit is contained in:
E. Stuart Hicks 2019-07-08 14:32:00 -04:00
parent 1387f7b7eb
commit 3b0c523e49
8 changed files with 54 additions and 3 deletions

View file

@ -40,6 +40,7 @@ type Config struct {
ProxyRedirectTo string `json:"proxyRedirectTo"`
RequestBuffering string `json:"requestBuffering"`
ProxyBuffering string `json:"proxyBuffering"`
ProxyHTTPVersion string `json:"proxyHTTPVersion"`
}
// Equal tests for equality between two Configuration types
@ -95,6 +96,9 @@ func (l1 *Config) Equal(l2 *Config) bool {
if l1.ProxyBuffering != l2.ProxyBuffering {
return false
}
if l1.ProxyHTTPVersion != l2.ProxyHTTPVersion {
return false
}
return true
}
@ -191,5 +195,10 @@ func (a proxy) Parse(ing *networking.Ingress) (interface{}, error) {
config.ProxyBuffering = defBackend.ProxyBuffering
}
config.ProxyHTTPVersion, err = parser.GetStringAnnotation("proxy-http-version", ing)
if err != nil {
config.ProxyHTTPVersion = defBackend.ProxyHTTPVersion
}
return config, nil
}

View file

@ -81,6 +81,7 @@ func (m mockBackend) GetDefaultBackend() defaults.Backend {
ProxyNextUpstreamTries: 3,
ProxyRequestBuffering: "on",
ProxyBuffering: "off",
ProxyHTTPVersion: "1.1",
}
}
@ -99,6 +100,7 @@ func TestProxy(t *testing.T) {
data[parser.GetAnnotationWithPrefix("proxy-next-upstream-tries")] = "3"
data[parser.GetAnnotationWithPrefix("proxy-request-buffering")] = "off"
data[parser.GetAnnotationWithPrefix("proxy-buffering")] = "on"
data[parser.GetAnnotationWithPrefix("proxy-http-version")] = "1.0"
ing.SetAnnotations(data)
i, err := NewParser(mockBackend{}).Parse(ing)
@ -142,6 +144,9 @@ func TestProxy(t *testing.T) {
if p.ProxyBuffering != "on" {
t.Errorf("expected on as proxy-buffering but returned %v", p.ProxyBuffering)
}
if p.ProxyHTTPVersion != "1.0" {
t.Errorf("expected 1.0 as proxy-http-version but returned %v", p.ProxyHTTPVersion)
}
}
func TestProxyWithNoAnnotation(t *testing.T) {
@ -188,4 +193,7 @@ func TestProxyWithNoAnnotation(t *testing.T) {
if p.RequestBuffering != "on" {
t.Errorf("expected on as request-buffering but returned %v", p.RequestBuffering)
}
if p.ProxyHTTPVersion != "1.1" {
t.Errorf("expected 1.1 as proxy-http-version but returned %v", p.ProxyHTTPVersion)
}
}