Skip to content

srcache_store_max_size as complex value type #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ngx_http_srcache_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static ngx_command_t ngx_http_srcache_commands[] = {
{ ngx_string("srcache_store_max_size"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
ngx_http_set_complex_value_size_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_srcache_loc_conf_t, store_max_size),
NULL },
Expand Down Expand Up @@ -269,7 +269,6 @@ ngx_http_srcache_create_loc_conf(ngx_conf_t *cf)
conf->store = NGX_CONF_UNSET_PTR;

conf->buf_size = NGX_CONF_UNSET_SIZE;
conf->store_max_size = NGX_CONF_UNSET_SIZE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conf->store_max_size = NGX_CONF_UNSET_PTR;

conf->header_buf_size = NGX_CONF_UNSET_SIZE;

conf->req_cache_control = NGX_CONF_UNSET;
Expand Down Expand Up @@ -305,7 +304,7 @@ ngx_http_srcache_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_size_value(conf->buf_size, prev->buf_size,
(size_t) ngx_pagesize);

ngx_conf_merge_size_value(conf->store_max_size, prev->store_max_size, 0);
ngx_conf_merge_ptr_value(conf->store_max_size, prev->store_max_size, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ngx_conf_merge_ptr_value(conf->store_max_size, prev->store_max_size, 0);
ngx_conf_merge_ptr_value(conf->store_max_size, prev->store_max_size, NULL);


ngx_conf_merge_size_value(conf->header_buf_size, prev->header_buf_size,
(size_t) ngx_pagesize);
Expand All @@ -322,6 +321,10 @@ ngx_http_srcache_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->store_statuses = prev->store_statuses;
}

if (conf->store_max_size == NULL) {
conf->store_max_size = prev->store_max_size;
}

Comment on lines +324 to +327
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (conf->store_max_size == NULL) {
conf->store_max_size = prev->store_max_size;
}

if (conf->cache_methods == 0) {
conf->cache_methods = prev->cache_methods;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ngx_http_srcache_filter_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef struct {
ngx_http_srcache_request_t *fetch;
ngx_http_srcache_request_t *store;
size_t buf_size;
size_t store_max_size;
ngx_http_complex_value_t *store_max_size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ngx_http_complex_value_t *store_max_size;
ngx_http_complex_value_t *store_max_size;

size_t header_buf_size;

ngx_http_complex_value_t *fetch_skip;
Expand Down Expand Up @@ -105,6 +105,7 @@ struct ngx_http_srcache_ctx_s {
ngx_chain_t *body_to_cache;
size_t response_length;
size_t response_body_length;
size_t store_max_size;
void *store_wev_handler_ctx;

ngx_int_t (*process_header)(ngx_http_request_t *r,
Expand Down
14 changes: 8 additions & 6 deletions src/ngx_http_srcache_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,18 @@ ngx_http_srcache_header_filter(ngx_http_request_t *r)
}
}

if (slcf->store_max_size != 0
ctx->store_max_size = ngx_http_complex_value_size(r, slcf->store_max_size, 0);

if (ctx->store_max_size != 0
&& r->headers_out.content_length_n > 0
&& r->headers_out.content_length_n + 15
/* just an approxiation for the response header size */
> (off_t) slcf->store_max_size)
> (off_t) ctx->store_max_size)
{
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"srcache_store bypassed because of too large "
"Content-Length response header: %O (limit is: %z)",
r->headers_out.content_length_n, slcf->store_max_size);
r->headers_out.content_length_n, ctx->store_max_size);

return ngx_http_srcache_next_header_filter(r);
}
Expand Down Expand Up @@ -429,13 +431,13 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
}

if (slcf->store_max_size != 0
&& ctx->response_length > slcf->store_max_size)
if (ctx->store_max_size != 0
&& ctx->response_length > ctx->store_max_size)
{
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"srcache_store bypassed because response body "
"exceeded maximum size: %z (limit is: %z)",
ctx->response_length, slcf->store_max_size);
ctx->response_length, ctx->store_max_size);

ctx->store_response = 0;

Expand Down