Welcome! Log In Create A New Profile

Advanced

Copy regex unnamed captures to cloned subrequests

Roman Arutyunyan
December 11, 2018 09:54AM
details: https://hg.nginx.org/nginx/rev/81d49f85afed
branches:
changeset: 7427:81d49f85afed
user: Roman Arutyunyan <arut@nginx.com>
date: Tue Dec 11 13:09:00 2018 +0300
description:
Copy regex unnamed captures to cloned subrequests.

Previously, unnamed regex captures matched in the parent request, were not
available in a cloned subrequest. Now 3 fields related to unnamed captures
are copied to a cloned subrequest: r->ncaptures, r->captures and
r->captures_data. Since r->captures cannot be changed by either request after
creating a clone, a new flag r->realloc_captures is introduced to force
reallocation of r->captures.

The issue was reported as a proxy_cache_background_update misbehavior in
http://mailman.nginx.org/pipermail/nginx/2018-December/057251.html.

diffstat:

src/http/ngx_http_core_module.c | 8 ++++++++
src/http/ngx_http_request.h | 4 ++++
src/http/ngx_http_variables.c | 4 +++-
3 files changed, 15 insertions(+), 1 deletions(-)

diffs (47 lines):

diff -r 4722b4b8aa93 -r 81d49f85afed src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c Tue Dec 11 13:12:35 2018 +0300
+++ b/src/http/ngx_http_core_module.c Tue Dec 11 13:09:00 2018 +0300
@@ -2386,6 +2386,14 @@ ngx_http_subrequest(ngx_http_request_t *
sr->phase_handler = r->phase_handler;
sr->write_event_handler = ngx_http_core_run_phases;

+#if (NGX_PCRE)
+ sr->ncaptures = r->ncaptures;
+ sr->captures = r->captures;
+ sr->captures_data = r->captures_data;
+ sr->realloc_captures = 1;
+ r->realloc_captures = 1;
+#endif
+
ngx_http_update_location_config(sr);
}

diff -r 4722b4b8aa93 -r 81d49f85afed src/http/ngx_http_request.h
--- a/src/http/ngx_http_request.h Tue Dec 11 13:12:35 2018 +0300
+++ b/src/http/ngx_http_request.h Tue Dec 11 13:09:00 2018 +0300
@@ -499,6 +499,10 @@ struct ngx_http_request_s {
unsigned gzip_vary:1;
#endif

+#if (NGX_PCRE)
+ unsigned realloc_captures:1;
+#endif
+
unsigned proxy:1;
unsigned bypass_cache:1;
unsigned no_cache:1;
diff -r 4722b4b8aa93 -r 81d49f85afed src/http/ngx_http_variables.c
--- a/src/http/ngx_http_variables.c Tue Dec 11 13:12:35 2018 +0300
+++ b/src/http/ngx_http_variables.c Tue Dec 11 13:09:00 2018 +0300
@@ -2504,7 +2504,9 @@ ngx_http_regex_exec(ngx_http_request_t *
if (re->ncaptures) {
len = cmcf->ncaptures;

- if (r->captures == NULL) {
+ if (r->captures == NULL || r->realloc_captures) {
+ r->realloc_captures = 0;
+
r->captures = ngx_palloc(r->pool, len * sizeof(int));
if (r->captures == NULL) {
return NGX_ERROR;


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Copy regex unnamed captures to cloned subrequests

Roman Arutyunyan 359 December 11, 2018 09:54AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 268
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready