Merge pull request #3409 from Shopify/client-max-body-size

Convert isValidClientBodyBufferSize to something more generic
This commit is contained in:
k8s-ci-robot 2018-11-13 08:36:06 -08:00 committed by GitHub
commit a22c656f30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 15 deletions

View file

@ -151,7 +151,7 @@ var (
"serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} {
return struct{ First, Second interface{} }{all, server}
},
"isValidClientBodyBufferSize": isValidClientBodyBufferSize,
"isValidByteSize": isValidByteSize,
"buildForwardedFor": buildForwardedFor,
"buildAuthSignURL": buildAuthSignURL,
"buildOpentracing": buildOpentracing,
@ -753,7 +753,7 @@ func buildNextUpstream(i, r interface{}) string {
return strings.Join(nextUpstreamCodes, " ")
}
func isValidClientBodyBufferSize(input interface{}) bool {
func isValidByteSize(input interface{}) bool {
s, ok := input.(string)
if !ok {
glog.Errorf("expected an 'string' type but %T was returned", input)
@ -761,6 +761,7 @@ func isValidClientBodyBufferSize(input interface{}) bool {
}
if s == "" {
glog.Errorf("empty byte size, hence it will not be set.")
return false
}
@ -780,7 +781,7 @@ func isValidClientBodyBufferSize(input interface{}) bool {
return true
}
glog.Errorf("client-body-buffer-size '%v' was provided in an incorrect format, hence it will not be set.", s)
glog.Errorf("incorrect byte size format '%v', hence it will not be set.", s)
return false
}

View file

@ -557,40 +557,40 @@ func TestBuildDenyVariable(t *testing.T) {
}
}
func TestBuildClientBodyBufferSize(t *testing.T) {
a := isValidClientBodyBufferSize("1000")
func TestBuildByteSize(t *testing.T) {
a := isValidByteSize("1000")
if !a {
t.Errorf("Expected '%v' but returned '%v'", true, a)
}
b := isValidClientBodyBufferSize("1000k")
b := isValidByteSize("1000k")
if !b {
t.Errorf("Expected '%v' but returned '%v'", true, b)
}
c := isValidClientBodyBufferSize("1000m")
c := isValidByteSize("1000m")
if !c {
t.Errorf("Expected '%v' but returned '%v'", true, c)
}
d := isValidClientBodyBufferSize("1000km")
d := isValidByteSize("1000km")
if d {
t.Errorf("Expected '%v' but returned '%v'", false, d)
}
e := isValidClientBodyBufferSize("1000mk")
e := isValidByteSize("1000mk")
if e {
t.Errorf("Expected '%v' but returned '%v'", false, e)
}
f := isValidClientBodyBufferSize("1000kk")
f := isValidByteSize("1000kk")
if f {
t.Errorf("Expected '%v' but returned '%v'", false, f)
}
g := isValidClientBodyBufferSize("1000mm")
g := isValidByteSize("1000mm")
if g {
t.Errorf("Expected '%v' but returned '%v'", false, g)
}
h := isValidClientBodyBufferSize(nil)
h := isValidByteSize(nil)
if h {
t.Errorf("Expected '%v' but returned '%v'", false, h)
}
i := isValidClientBodyBufferSize("")
i := isValidByteSize("")
if i {
t.Errorf("Expected '%v' but returned '%v'", false, i)
}

View file

@ -874,8 +874,10 @@ stream {
proxy_http_version 1.1;
proxy_ssl_server_name on;
proxy_pass_request_headers on;
{{ if isValidByteSize $location.Proxy.BodySize }}
client_max_body_size {{ $location.Proxy.BodySize }};
{{ if isValidClientBodyBufferSize $location.ClientBodyBufferSize }}
{{ end }}
{{ if isValidByteSize $location.ClientBodyBufferSize }}
client_body_buffer_size {{ $location.ClientBodyBufferSize }};
{{ end }}
@ -1084,8 +1086,10 @@ stream {
}
{{ end }}
{{ if isValidByteSize $location.Proxy.BodySize }}
client_max_body_size {{ $location.Proxy.BodySize }};
{{ if isValidClientBodyBufferSize $location.ClientBodyBufferSize }}
{{ end }}
{{ if isValidByteSize $location.ClientBodyBufferSize }}
client_body_buffer_size {{ $location.ClientBodyBufferSize }};
{{ end }}