From 0f3e2b9bf09602d0d7d6899766ba2fe9608268e9 Mon Sep 17 00:00:00 2001 From: Maxime Ginters Date: Fri, 9 Nov 2018 09:45:11 -0500 Subject: [PATCH] Convert isValidClientBodyBufferSize to something more generic and use it for client_max_body_size --- .../ingress/controller/template/template.go | 7 ++++--- .../controller/template/template_test.go | 20 +++++++++---------- rootfs/etc/nginx/template/nginx.tmpl | 8 ++++++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 393df6c04..c0e34e2b7 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -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 } diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index 2da1c25c6..385ed7359 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -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) } diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index feb3966c1..8ce3a7bb9 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -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 }}