Skip to content

Commit ff59b80

Browse files
author
Andre
committed
Check for store_max_size in body filter too
agentzh suggested to check store_max_size in the body filter too because of modules that don't set content_length. also adjusted coding style and made store_max_size check against 0 instead of undef.
1 parent e7677b2 commit ff59b80

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Known Issues
9494
set $key ...;
9595
srcache_fetch GET /memc $key;
9696
srcache_store PUT /memc $key;
97-
srcache_store_max_size 1m;
97+
srcache_store_max_size 1m;
9898

9999
# proxy_pass/fastcgi_pass/...
100100
}

src/ngx_http_srcache_filter_module.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ ngx_http_srcache_header_filter(ngx_http_request_t *r)
205205
return ngx_http_next_header_filter(r);
206206
}
207207

208-
if (slcf->store_max_size != NGX_CONF_UNSET_SIZE
209-
&& r->headers_out.content_length_n >= (int) slcf->store_max_size) {
210-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
211-
"bypass because of too large content: %d (limit is: %d)",
212-
r->headers_out.content_length, slcf->store_max_size);
213-
return ngx_http_next_header_filter(r);
214-
}
208+
if (slcf->store_max_size != 0
209+
&& r->headers_out.content_length_n >= (int) slcf->store_max_size) {
210+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
211+
"bypass because of too large content-length header: %d (limit is: %d)",
212+
r->headers_out.content_length_n, slcf->store_max_size);
213+
return ngx_http_next_header_filter(r);
214+
}
215215

216216
dd("try to save the response header");
217217

@@ -292,11 +292,12 @@ ngx_http_srcache_header_filter(ngx_http_request_t *r)
292292
static ngx_int_t
293293
ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
294294
{
295-
ngx_http_request_t *pr;
296-
ngx_http_srcache_ctx_t *ctx, *pr_ctx;
297-
ngx_int_t rc;
298-
ngx_chain_t *cl;
299-
ngx_flag_t last;
295+
ngx_http_request_t *pr;
296+
ngx_http_srcache_ctx_t *ctx, *pr_ctx;
297+
ngx_int_t rc;
298+
ngx_chain_t *cl;
299+
ngx_flag_t last;
300+
ngx_http_srcache_loc_conf_t *slcf;
300301

301302

302303
dd_enter();
@@ -381,6 +382,16 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
381382
}
382383
}
383384

385+
slcf = ngx_http_get_module_loc_conf(r, ngx_http_srcache_filter_module);
386+
if (slcf->store_max_size != 0
387+
&& ctx->body_length >= slcf->store_max_size) {
388+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
389+
"bypass because body reached maximum size: %d (limit is: %d)",
390+
ctx->body_length, slcf->store_max_size);
391+
ctx->store_response = 0;
392+
goto done;
393+
}
394+
384395
rc = ngx_http_srcache_add_copy_chain(r->pool, &ctx->body_to_cache, in);
385396

386397
if (rc != NGX_OK) {
@@ -473,7 +484,7 @@ ngx_http_srcache_create_loc_conf(ngx_conf_t *cf)
473484

474485
slcf->buf_size = NGX_CONF_UNSET_SIZE;
475486

476-
slcf->store_max_size = NGX_CONF_UNSET_SIZE;
487+
slcf->store_max_size = NGX_CONF_UNSET_SIZE;
477488

478489
return slcf;
479490
}
@@ -492,7 +503,7 @@ ngx_http_srcache_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
492503
(size_t) ngx_pagesize);
493504

494505
ngx_conf_merge_size_value(conf->store_max_size, prev->store_max_size,
495-
NGX_CONF_UNSET_SIZE);
506+
0);
496507

497508
return NGX_CONF_OK;
498509
}

src/ngx_http_srcache_filter_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef struct {
2929
ngx_http_srcache_request_t *fetch;
3030
ngx_http_srcache_request_t *store;
3131
size_t buf_size;
32-
size_t store_max_size;
32+
size_t store_max_size;
3333

3434
unsigned postponed_to_access_phase_end;
3535
} ngx_http_srcache_loc_conf_t;

0 commit comments

Comments
 (0)