Skip to content

Commit 029f427

Browse files
authored
feat: allow to set client_max_body_size to 0 (#11)
1 parent bc257a5 commit 029f427

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/ngx_http_apisix_module.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ ngx_http_apisix_client_set_max_body_size(ngx_http_request_t *r,
304304
ctx->client_max_body_size);
305305

306306
ctx->client_max_body_size = bytes;
307+
ctx->client_max_body_size_set = 1;
307308

308309
return NGX_OK;
309310
}
@@ -317,7 +318,7 @@ ngx_http_apisix_client_max_body_size(ngx_http_request_t *r)
317318

318319
ctx = ngx_http_get_module_ctx(r, ngx_http_apisix_module);
319320

320-
if (ctx != NULL && ctx->client_max_body_size) {
321+
if (ctx != NULL && ctx->client_max_body_size_set) {
321322
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
322323
"get client max body size %O",
323324
ctx->client_max_body_size);

src/ngx_http_apisix_module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ typedef struct {
1515
EVP_PKEY *upstream_pkey;
1616

1717
off_t client_max_body_size;
18+
19+
unsigned client_max_body_size_set:1;
1820
} ngx_http_apisix_ctx_t;
1921

2022

t/client.t

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,22 @@ POST /t
215215
--- error_code: 413
216216
--- error_log
217217
client intended to send too large body
218+
219+
220+
221+
=== TEST 11: set client_max_body_size to 0 means no limitation
222+
--- config
223+
location /up {
224+
return 200;
225+
}
226+
location /t {
227+
client_max_body_size 1;
228+
access_by_lua_block {
229+
local client = require("resty.apisix.client")
230+
assert(client.set_client_max_body_size(0))
231+
}
232+
proxy_pass http://127.0.0.1:1984/up;
233+
}
234+
--- request
235+
POST /t
236+
1234

0 commit comments

Comments
 (0)