Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert isValidClientBodyBufferSize to something more generic #3409

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -753,14 +753,15 @@ 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)
return false
}

if s == "" {
glog.Errorf("empty byte size, hence it will not be set.")
return false
}

Expand All @@ -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
}

Expand Down
20 changes: 10 additions & 10 deletions internal/ingress/controller/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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 }}

Expand Down