Response size clamp (#786)

*) Limit response http body or json response size to FN_MAX_RESPONSE_SIZE (default unlimited)
*) If limits are exceeded 502 is returned with 'body too large' in the error message
This commit is contained in:
Tolga Ceylan
2018-03-01 17:14:50 -08:00
committed by GitHub
parent a30c2c8f1b
commit 89a1fc7c72
7 changed files with 92 additions and 18 deletions

View File

@@ -12,6 +12,7 @@ type AgentConfig struct {
MinDockerVersion string `json:"min_docker_version"`
FreezeIdleMsecs time.Duration `json:"freeze_idle_msecs"`
EjectIdleMsecs time.Duration `json:"eject_idle_msecs"`
MaxResponseSize uint64 `json:"max_response_size"`
}
func NewAgentConfig() (*AgentConfig, error) {
@@ -36,6 +37,16 @@ func NewAgentConfig() (*AgentConfig, error) {
return cfg, errors.New("error eject idle delay cannot be zero")
}
if size := os.Getenv("FN_MAX_RESPONSE_SIZE"); size != "" {
cfg.MaxResponseSize, err = strconv.ParseUint(size, 10, 64)
if err != nil {
return cfg, errors.New("error initializing response buffer size")
}
if cfg.MaxResponseSize < 0 {
return cfg, errors.New("error invalid response buffer size")
}
}
return cfg, nil
}