Skip to content

Commit

Permalink
use 0 to indicate unlimited
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Aug 2, 2024
1 parent f489675 commit 50a4ac3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion changelog/unreleased/kong/feat-pdk-unlimited-body-size.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
message: Added negative value to support unlimited body size. When parameter `max_allowed_file_size` is negative, `get_raw_body` will return the entire body, but the size of this body will still be limited by Nginx's `client_max_body_size`.
message: Added `0` to support unlimited body size. When parameter `max_allowed_file_size` is `0`, `get_raw_body` will return the entire body, but the size of this body will still be limited by Nginx's `client_max_body_size`.
type: feature
scope: PDK
8 changes: 4 additions & 4 deletions kong/pdk/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,14 @@ local function new(self)
-- If the size of the body is greater than the Nginx buffer size (set by
-- `client_body_buffer_size`), this function fails and returns an error
-- message explaining this limitation, unless `max_allowed_file_size`
-- is set and less than 0 or larger than the body size buffered to disk.
-- is set and equal to 0 or larger than the body size buffered to disk.
-- Use of `max_allowed_file_size` requires Kong to read data from filesystem
-- and has performance implications.
--
-- @function kong.request.get_raw_body
-- @phases rewrite, access, response, admin_api
-- @max_allowed_file_size[opt] number the max allowed file size to be read from,
-- less than zero means no limit, but the size of this body will still be limited
-- 0 means unlimited, but the size of this body will still be limited
-- by Nginx's client_max_body_size.
-- @treturn string|nil The plain request body or nil if it does not fit into
-- the NGINX temporary buffer.
Expand All @@ -723,7 +723,7 @@ local function new(self)
return ""
end

if not max_allowed_file_size then
if not max_allowed_file_size or max_allowed_file_size < 0 then
return nil, "request body did not fit into client body buffer, consider raising 'client_body_buffer_size'"
end

Expand All @@ -733,7 +733,7 @@ local function new(self)
end

local size = file:seek("end") or 0
if max_allowed_file_size >= 0 and size > max_allowed_file_size then
if max_allowed_file_size > 0 and size > max_allowed_file_size then
return nil, ("request body file too big: %d > %d"):format(size, max_allowed_file_size)
end

Expand Down
4 changes: 2 additions & 2 deletions t/01-pdk/04-request/15-get_raw_body.t
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ body err: request body file too big: 20000 > 19999
=== TEST 8: request.get_raw_body() returns correctly if max_allowed_file_size is less than 0
=== TEST 8: request.get_raw_body() returns correctly if max_allowed_file_size is equal to 0
--- http_config eval: $t::Util::HttpConfig
--- config
location = /t {
access_by_lua_block {
local PDK = require "kong.pdk"
local pdk = PDK.new()
local body, err = pdk.request.get_raw_body(-1)
local body, err = pdk.request.get_raw_body(0)
if body then
ngx.say("body length: ", #body)
Expand Down

0 comments on commit 50a4ac3

Please sign in to comment.