Skip to content

Commit 66a087b

Browse files
committed
reupdate to disable enable subrequest feature, control nginx-link-function's subrequest feature only available on nginx version 1.13.10 and abv
1 parent 82776ee commit 66a087b

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ if [ $ngx_found != yes ]; then
6969
echo "nginx version not support this module, please make sure nginx version is 1.10 and above"
7070
echo
7171
exit 1
72+
else
73+
have=NGX_LINK_FUNC_SUBREQ . auto/have
7274
fi
7375

7476

src/ngx_link_func_module.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* Configs
4545
*
4646
*/
47-
#if (nginx_version > 1013003)
47+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
4848

4949
#define NGX_SUBREQ_NORMAL 0
5050
#define NGX_SUBREQ_CHECK_STATUS 1
@@ -99,7 +99,7 @@ typedef struct {
9999
ngx_http_complex_value_t value;
100100
} ngx_http_link_func_req_header_t;
101101

102-
#if (nginx_version > 1013003)
102+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
103103
typedef struct {
104104
ngx_str_t uri;
105105
// ngx_uint_t flag;
@@ -113,7 +113,7 @@ typedef struct {
113113
ngx_str_t _method_name;
114114
ngx_http_link_func_app_handler _handler;
115115
ngx_array_t *ext_req_headers;
116-
#if (nginx_version > 1013003)
116+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
117117
ngx_array_t *subrequests;
118118
#endif
119119
// ngx_msec_t proc_timeout;
@@ -130,7 +130,7 @@ typedef struct {
130130
ngx_str_t content_type;
131131
ngx_buf_t *resp_content;
132132
ngx_int_t rc;
133-
#if (nginx_version > 1013003)
133+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
134134
ngx_uint_t subreq_curr_index;
135135
// ngx_uint_t subreq_parallel_wait_cnt;
136136
ngx_uint_t subreq_sequential_wait_cnt;
@@ -156,7 +156,7 @@ static void * ngx_http_link_func_create_loc_conf(ngx_conf_t *cf);
156156
static char * ngx_http_link_func_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);
157157
static char *ngx_http_link_func_ext_req_headers_add_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
158158
static char *ngx_http_link_func_init_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
159-
#if (nginx_version > 1013003)
159+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
160160
static char *ngx_http_link_func_subrequest_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
161161
// static ngx_int_t ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc);
162162
static ngx_int_t ngx_http_link_func_subrequest_done(ngx_http_request_t *r, void *data, ngx_int_t rc);
@@ -278,7 +278,7 @@ static ngx_command_t ngx_http_link_func_commands[] = {
278278
0,
279279
NULL
280280
},
281-
#if (nginx_version > 1013003)
281+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
282282
{ ngx_string("ngx_link_func_subrequest"), /* directive */
283283
NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_1MORE, /* location context and takes up to 4 arguments*/
284284
ngx_http_link_func_subrequest_cmd, /* configuration setup function */
@@ -517,7 +517,7 @@ ngx_http_link_func_ext_req_headers_add_cmd(ngx_conf_t *cf, ngx_command_t *cmd, v
517517
return NGX_CONF_OK;
518518
}
519519

520-
#if (nginx_version > 1013003)
520+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
521521

522522
static char *
523523
ngx_http_link_func_subrequest_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
@@ -1021,7 +1021,7 @@ ngx_http_link_func_create_loc_conf(ngx_conf_t *cf) {
10211021
}
10221022

10231023
conf->ext_req_headers = NGX_CONF_UNSET_PTR;
1024-
#if (nginx_version > 1013003)
1024+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
10251025
conf->subrequests = NGX_CONF_UNSET_PTR;
10261026
#endif
10271027
return conf;
@@ -1035,7 +1035,7 @@ ngx_http_link_func_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) {
10351035
ngx_http_link_func_loc_conf_t *conf = child;
10361036

10371037
ngx_conf_merge_ptr_value(conf->ext_req_headers, prev->ext_req_headers, NULL);
1038-
#if (nginx_version > 1013003)
1038+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
10391039
ngx_conf_merge_ptr_value(conf->subrequests, prev->subrequests, NULL);
10401040
#endif
10411041
// ngx_conf_merge_str_value(conf->_method_name, prev->_method_name, "");
@@ -1088,14 +1088,13 @@ ngx_http_link_func_after_process(ngx_event_t *ev) {
10881088
r->main->blocked--;
10891089
r->aio = 0;
10901090

1091-
// Force to run core run phase to avoid write handler is empty handler
1092-
// r->write_event_handler(r);
1093-
ngx_http_core_run_phases(r);
1091+
r->write_event_handler(r);
1092+
// ngx_http_core_run_phases(r);
10941093
ngx_http_run_posted_requests(c);
10951094
}
10961095
#endif
10971096

1098-
#if (nginx_version > 1013003)
1097+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
10991098
// static ngx_int_t
11001099
// ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc) {
11011100
// ngx_http_link_func_internal_ctx_t *ctx = data;
@@ -1161,7 +1160,7 @@ ngx_http_link_func_process_subrequest(ngx_http_request_t *r, ngx_http_link_func_
11611160

11621161
ctx->subreq_curr_index++;
11631162

1164-
if (ngx_http_subrequest(r, &subreq->uri, args, &sr, ps, NGX_HTTP_SUBREQUEST_WAITED) == NGX_ERROR) {
1163+
if (ngx_http_subrequest(r, &subreq->uri, args, &sr, ps, NGX_HTTP_SUBREQUEST_WAITED | NGX_HTTP_SUBREQUEST_IN_MEMORY ) == NGX_ERROR) {
11651164
return NGX_ERROR;
11661165
}
11671166

@@ -1204,7 +1203,7 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
12041203
ngx_http_link_func_internal_ctx_t *internal_ctx;
12051204
ngx_link_func_ctx_t *new_ctx;
12061205

1207-
#if (nginx_version > 1013003)
1206+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
12081207
ngx_int_t rc;
12091208
ngx_uint_t i;//, n_sub_reqs;
12101209
ngx_http_link_func_subreq_conf_t *subreqs, *subreq;
@@ -1226,6 +1225,7 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
12261225
}
12271226

12281227
#if (nginx_version > 1013003)
1228+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
12291229
if ( lcf->subrequests ) {
12301230

12311231
if (internal_ctx->subreq_sequential_wait_cnt) {
@@ -1260,13 +1260,14 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
12601260
// if (internal_ctx->subreq_parallel_wait_cnt) {
12611261
// return NGX_DONE;
12621262
// }
1263-
}
1263+
}
12641264

12651265
if (lcf->_handler == NULL) {
12661266
// ngx_http_finalize_request(r, NGX_DONE);
12671267
return NGX_DECLINED;
12681268
}
1269-
1269+
#endif
1270+
#if (NGX_THREADS)
12701271
if (internal_ctx->rc == NGX_CONF_UNSET) {
12711272
goto new_task;
12721273
}
@@ -1276,9 +1277,8 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
12761277
} else {
12771278
return NGX_DECLINED;
12781279
}
1279-
1280-
12811280
new_task:
1281+
#endif
12821282
#endif
12831283
new_ctx = ngx_pcalloc(r->pool, sizeof(ngx_link_func_ctx_t));
12841284
new_ctx->__r__ = r;
@@ -1405,7 +1405,9 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
14051405
return NGX_ERROR;
14061406
}
14071407
r->main->blocked++;
1408-
r->aio = 1;
1408+
r->aio = 1;
1409+
// Force to run core run phase to avoid write handler is empty handler
1410+
r->write_event_handler = ngx_http_core_run_phases;
14091411
return NGX_DONE;
14101412
single_thread:
14111413
#else
@@ -1540,7 +1542,7 @@ ngx_http_link_func_rewrite_handler(ngx_http_request_t *r) {
15401542
ngx_http_link_func_parse_ext_request_headers(r, lcf->ext_req_headers);
15411543
}
15421544

1543-
#if (nginx_version > 1013003)
1545+
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
15441546
if (lcf->_handler == NULL && lcf->subrequests == NULL) {
15451547
return NGX_DECLINED;
15461548
}

0 commit comments

Comments
 (0)