be consistent with what Nginx supports
This commit is contained in:
parent
ccd7b890fd
commit
4eabd535f9
3 changed files with 32 additions and 20 deletions
|
@ -727,11 +727,15 @@ func buildNextUpstream(i, r interface{}) string {
|
|||
return strings.Join(nextUpstreamCodes, " ")
|
||||
}
|
||||
|
||||
var sizeUnitRegex = regexp.MustCompile("^[0-9]+[kKmMgG]{0,1}$")
|
||||
// refer to http://nginx.org/en/docs/syntax.html
|
||||
// Nginx differentiates between size and offset
|
||||
// offset directives support gigabytes in addition
|
||||
var nginxSizeRegex = regexp.MustCompile("^[0-9]+[kKmM]{0,1}$")
|
||||
var nginxOffsetRegex = regexp.MustCompile("^[0-9]+[kKmMgG]{0,1}$")
|
||||
|
||||
// isValidByteSize validates size units valid in nginx
|
||||
// http://nginx.org/en/docs/syntax.html
|
||||
func isValidByteSize(input interface{}) bool {
|
||||
func isValidByteSize(input interface{}, isOffset bool) bool {
|
||||
s, ok := input.(string)
|
||||
if !ok {
|
||||
glog.Errorf("expected an 'string' type but %T was returned", input)
|
||||
|
@ -744,7 +748,11 @@ func isValidByteSize(input interface{}) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
return sizeUnitRegex.MatchString(s)
|
||||
if isOffset {
|
||||
return nginxOffsetRegex.MatchString(s)
|
||||
}
|
||||
|
||||
return nginxSizeRegex.MatchString(s)
|
||||
}
|
||||
|
||||
type ingressInformation struct {
|
||||
|
|
|
@ -559,24 +559,28 @@ func TestBuildDenyVariable(t *testing.T) {
|
|||
|
||||
func TestBuildByteSize(t *testing.T) {
|
||||
cases := []struct {
|
||||
input interface{}
|
||||
value interface{}
|
||||
isOffset bool
|
||||
expected bool
|
||||
}{
|
||||
{"1000", true},
|
||||
{"1000k", true},
|
||||
{"1m", true},
|
||||
{"10g", true},
|
||||
{" 1m ", true},
|
||||
{"1000kk", false},
|
||||
{"1000km", false},
|
||||
{"1mm", false},
|
||||
{nil, false},
|
||||
{"", false},
|
||||
{" ", false},
|
||||
{"1000", false, true},
|
||||
{"1000k", false, true},
|
||||
{"1m", false, true},
|
||||
{"10g", false, false},
|
||||
{" 1m ", false, true},
|
||||
{"1000kk", false, false},
|
||||
{"1000km", false, false},
|
||||
{"1mm", false, false},
|
||||
{nil, false, false},
|
||||
{"", false, false},
|
||||
{" ", false, false},
|
||||
{"1G", true, true},
|
||||
{"1000kk", true, false},
|
||||
{"", true, false},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
val := isValidByteSize(tc.input)
|
||||
val := isValidByteSize(tc.value, tc.isOffset)
|
||||
if tc.expected != val {
|
||||
t.Errorf("Expected '%v' but returned '%v'", tc.expected, val)
|
||||
}
|
||||
|
|
|
@ -980,10 +980,10 @@ stream {
|
|||
proxy_http_version 1.1;
|
||||
proxy_ssl_server_name on;
|
||||
proxy_pass_request_headers on;
|
||||
{{ if isValidByteSize $location.Proxy.BodySize }}
|
||||
{{ if isValidByteSize $location.Proxy.BodySize true }}
|
||||
client_max_body_size {{ $location.Proxy.BodySize }};
|
||||
{{ end }}
|
||||
{{ if isValidByteSize $location.ClientBodyBufferSize }}
|
||||
{{ if isValidByteSize $location.ClientBodyBufferSize false }}
|
||||
client_body_buffer_size {{ $location.ClientBodyBufferSize }};
|
||||
{{ end }}
|
||||
|
||||
|
@ -1197,10 +1197,10 @@ stream {
|
|||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if isValidByteSize $location.Proxy.BodySize }}
|
||||
{{ if isValidByteSize $location.Proxy.BodySize true }}
|
||||
client_max_body_size {{ $location.Proxy.BodySize }};
|
||||
{{ end }}
|
||||
{{ if isValidByteSize $location.ClientBodyBufferSize }}
|
||||
{{ if isValidByteSize $location.ClientBodyBufferSize false }}
|
||||
client_body_buffer_size {{ $location.ClientBodyBufferSize }};
|
||||
{{ end }}
|
||||
|
||||
|
|
Loading…
Reference in a new issue