summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_core_module.c
diff options
context:
space:
mode:
authorRoman Arutyunyan <arut@nginx.com>2017-05-25 15:57:59 +0300
committerRoman Arutyunyan <arut@nginx.com>2017-05-25 15:57:59 +0300
commit8644d9491ad3c0eb16bcda1d452aba326e1f4dae (patch)
tree1425006b8569fe3059667742d484933ec9c0e7e5 /src/http/ngx_http_core_module.c
parentc83922b18ddc83f654c1d0df48a6ca1ee9938078 (diff)
downloadnginx-8644d9491ad3c0eb16bcda1d452aba326e1f4dae.tar.gz
nginx-8644d9491ad3c0eb16bcda1d452aba326e1f4dae.tar.bz2
Background subrequests for cache updates.
Previously, cache background update might not work as expected, making client wait for it to complete before receiving the final part of a stale response. This could happen if the response could not be sent to the client socket in one filter chain call. Now background cache update is done in a background subrequest. This type of subrequest does not block any other subrequests or the main request.
Diffstat (limited to 'src/http/ngx_http_core_module.c')
-rw-r--r--src/http/ngx_http_core_module.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index af67b7f85..7e40e7860 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -2518,6 +2518,7 @@ ngx_http_subrequest(ngx_http_request_t *r,
sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;
+ sr->background = (flags & NGX_HTTP_SUBREQUEST_BACKGROUND) != 0;
sr->unparsed_uri = r->unparsed_uri;
sr->method_name = ngx_http_core_get_method;
@@ -2531,29 +2532,31 @@ ngx_http_subrequest(ngx_http_request_t *r,
sr->read_event_handler = ngx_http_request_empty_handler;
sr->write_event_handler = ngx_http_handler;
- if (c->data == r && r->postponed == NULL) {
- c->data = sr;
- }
-
sr->variables = r->variables;
sr->log_handler = r->log_handler;
- pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
- if (pr == NULL) {
- return NGX_ERROR;
- }
+ if (!sr->background) {
+ if (c->data == r && r->postponed == NULL) {
+ c->data = sr;
+ }
- pr->request = sr;
- pr->out = NULL;
- pr->next = NULL;
+ pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
+ if (pr == NULL) {
+ return NGX_ERROR;
+ }
- if (r->postponed) {
- for (p = r->postponed; p->next; p = p->next) { /* void */ }
- p->next = pr;
+ pr->request = sr;
+ pr->out = NULL;
+ pr->next = NULL;
- } else {
- r->postponed = pr;
+ if (r->postponed) {
+ for (p = r->postponed; p->next; p = p->next) { /* void */ }
+ p->next = pr;
+
+ } else {
+ r->postponed = pr;
+ }
}
sr->internal = 1;