set /configuration client body size dynamically
This commit is contained in:
parent
b21c721196
commit
6a293c7e11
3 changed files with 62 additions and 33 deletions
|
@ -136,6 +136,7 @@ var (
|
||||||
"escapeLiteralDollar": escapeLiteralDollar,
|
"escapeLiteralDollar": escapeLiteralDollar,
|
||||||
"shouldConfigureLuaRestyWAF": shouldConfigureLuaRestyWAF,
|
"shouldConfigureLuaRestyWAF": shouldConfigureLuaRestyWAF,
|
||||||
"buildLuaSharedDictionaries": buildLuaSharedDictionaries,
|
"buildLuaSharedDictionaries": buildLuaSharedDictionaries,
|
||||||
|
"luaConfigurationRequestBodySize": luaConfigurationRequestBodySize,
|
||||||
"buildLocation": buildLocation,
|
"buildLocation": buildLocation,
|
||||||
"buildAuthLocation": buildAuthLocation,
|
"buildAuthLocation": buildAuthLocation,
|
||||||
"shouldApplyGlobalAuth": shouldApplyGlobalAuth,
|
"shouldApplyGlobalAuth": shouldApplyGlobalAuth,
|
||||||
|
@ -272,6 +273,22 @@ func buildLuaSharedDictionaries(c interface{}, s interface{}, disableLuaRestyWAF
|
||||||
return strings.Join(out, ";\n") + ";\n"
|
return strings.Join(out, ";\n") + ";\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func luaConfigurationRequestBodySize(c interface{}) string {
|
||||||
|
cfg, ok := c.(config.Configuration)
|
||||||
|
if !ok {
|
||||||
|
klog.Errorf("expected a 'config.Configuration' type but %T was returned", c)
|
||||||
|
return "100" // just a default number
|
||||||
|
}
|
||||||
|
|
||||||
|
size := cfg.LuaSharedDicts["configuration_data"]
|
||||||
|
if size < cfg.LuaSharedDicts["certificate_data"] {
|
||||||
|
size = cfg.LuaSharedDicts["certificate_data"]
|
||||||
|
}
|
||||||
|
size = size + 1
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d", size)
|
||||||
|
}
|
||||||
|
|
||||||
// configForLua returns some general configuration as Lua table represented as string
|
// configForLua returns some general configuration as Lua table represented as string
|
||||||
func configForLua(input interface{}) string {
|
func configForLua(input interface{}) string {
|
||||||
all, ok := input.(config.TemplateConfig)
|
all, ok := input.(config.TemplateConfig)
|
||||||
|
|
|
@ -225,6 +225,19 @@ func TestBuildLuaSharedDictionaries(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLuaConfigurationRequestBodySize(t *testing.T) {
|
||||||
|
cfg := config.Configuration{
|
||||||
|
LuaSharedDicts: map[string]int{
|
||||||
|
"configuration_data": 10, "certificate_data": 20,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
size := luaConfigurationRequestBodySize(cfg)
|
||||||
|
if "21" != size {
|
||||||
|
t.Errorf("expected the size to be 20 but got: %v", size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFormatIP(t *testing.T) {
|
func TestFormatIP(t *testing.T) {
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
Input, Output string
|
Input, Output string
|
||||||
|
|
|
@ -580,9 +580,8 @@ http {
|
||||||
}
|
}
|
||||||
|
|
||||||
location /configuration {
|
location /configuration {
|
||||||
# this should be equals to configuration_data dict
|
client_max_body_size {{ luaConfigurationRequestBodySize $cfg }}m;
|
||||||
client_max_body_size 10m;
|
client_body_buffer_size {{ luaConfigurationRequestBodySize $cfg }}m;
|
||||||
client_body_buffer_size 10m;
|
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
|
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
|
|
Loading…
Reference in a new issue