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

View file

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

View file

@ -874,8 +874,10 @@ stream {
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_ssl_server_name on; proxy_ssl_server_name on;
proxy_pass_request_headers on; proxy_pass_request_headers on;
{{ if isValidByteSize $location.Proxy.BodySize }}
client_max_body_size {{ $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 }}; client_body_buffer_size {{ $location.ClientBodyBufferSize }};
{{ end }} {{ end }}
@ -1084,8 +1086,10 @@ stream {
} }
{{ end }} {{ end }}
{{ if isValidByteSize $location.Proxy.BodySize }}
client_max_body_size {{ $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 }}; client_body_buffer_size {{ $location.ClientBodyBufferSize }};
{{ end }} {{ end }}