Skip to content

Commit

Permalink
feat(conf) configurable request body handling
Browse files Browse the repository at this point in the history
Add directives for client_max_body_size and client_body_buffer_size,
allowing users to work around request body read limitations without
the need to use a custom Nginx config.
  • Loading branch information
p0pr0ck5 committed Jun 6, 2017
1 parent 2452bbc commit 925eb86
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,27 @@
# `text/html`, `application/json`, and
# `application/xml`.

#client_max_body_size = 0 # Defines the maximum request body size allowed
# by Kong, specified in the Content-Length
# request header. If a request exceeds this
# limit, Kong will respond with a 413 (Request
# Entity Too Large). Setting this value to 0
# disables checking of request body size.

#client_body_buffer_size = 8k # Defines the buffer size for reading the
# request body. If the client request body is
# larger than this value, the body will be
# buffered to disk. Note that when the body is
# buffered to disk Kong plugins that access or
# manipulate the request body may not work, so
# it is advisable to set this value as high as
# possible (e.g., set it as high as
# `client_max_body_size` to force request
# bodies to be kept in memory). Do note that
# high-concurrency environments will require
# significant memory allocations to process
# many concurrent large request bodies.

#------------------------------------------------------------------------------
# DATASTORE
#------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ local CONF_INFERENCES = {
latency_tokens = {typ = "boolean"},
error_default_type = {enum = {"application/json", "application/xml",
"text/html", "text/plain"}},
client_max_body_size = {typ = "string"},

database = {enum = {"postgres", "cassandra"}},
pg_port = {typ = "number"},
Expand Down
2 changes: 2 additions & 0 deletions kong/templates/kong_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ upstream_keepalive = 60
server_tokens = on
latency_tokens = on
error_default_type = text/plain
client_max_body_size = 0
client_body_buffer_size = 8k
database = postgres
pg_host = 127.0.0.1
Expand Down
3 changes: 2 additions & 1 deletion kong/templates/nginx_kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};
>-- reset_timedout_connection on; # disabled until benchmarked
> end
client_max_body_size 0;
client_max_body_size ${{CLIENT_MAX_BODY_SIZE}};
proxy_ssl_server_name on;
underscores_in_headers on;
Expand Down Expand Up @@ -84,6 +84,7 @@ server {
access_log ${{PROXY_ACCESS_LOG}};
error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};
client_body_buffer_size ${{CLIENT_BODY_BUFFER_SIZE}};
> if ssl then
listen ${{PROXY_LISTEN_SSL}} ssl;
Expand Down

0 comments on commit 925eb86

Please sign in to comment.