|
46 | 46 | */ |
47 | 47 | #if (nginx_version > 1013003) |
48 | 48 |
|
49 | | -#define NGX_SUBREQ_SEQUENTIAL 0 |
50 | | -#define NGX_SUBREQ_PARALLEL 1 |
51 | | -#define NGX_SUBREQ_SEQUENTIAL_CHK 2 |
| 49 | +#define NGX_SUBREQ_NORMAL 0 |
| 50 | +#define NGX_SUBREQ_CHECK_STATUS 1 |
| 51 | +#define NGX_SUBREQ_INCL_BODY 2 |
| 52 | +#define NGX_SUBREQ_INCL_ARGS 3 |
52 | 53 |
|
53 | 54 | static ngx_conf_enum_t ngx_http_link_func_subrequest_flags[] = { |
54 | | - { ngx_string("sequential"), NGX_SUBREQ_SEQUENTIAL }, // subrequest run synchronizely but waiting for response |
55 | | - { ngx_string("sequential_check"), NGX_SUBREQ_SEQUENTIAL_CHK }, // subrequest run synchronizely but waiting for response and check status |
56 | | - { ngx_string("parallel"), NGX_SUBREQ_PARALLEL }, // subrequest run parallely but waiting for response |
| 55 | + { ngx_string("check_status"), NGX_SUBREQ_CHECK_STATUS }, // subrequest run synchronizely but waiting for response and check status |
| 56 | + { ngx_string("incl_body"), NGX_SUBREQ_INCL_BODY }, // include body with the subrequest |
| 57 | + { ngx_string("incl_args"), NGX_SUBREQ_INCL_ARGS }, // include args with the subrequest |
| 58 | + // { ngx_string("parallel"), NGX_SUBREQ_PARALLEL }, // subrequest run parallely but waiting for response |
57 | 59 | { ngx_null_string, 0 } |
58 | 60 | }; |
59 | 61 | #endif |
@@ -100,9 +102,10 @@ typedef struct { |
100 | 102 | #if (nginx_version > 1013003) |
101 | 103 | typedef struct { |
102 | 104 | ngx_str_t uri; |
103 | | - ngx_uint_t flag; |
| 105 | + // ngx_uint_t flag; |
104 | 106 | ngx_flag_t incl_args; |
105 | 107 | ngx_flag_t incl_body; |
| 108 | + ngx_flag_t check_status; |
106 | 109 | } ngx_http_link_func_subreq_conf_t; |
107 | 110 | #endif |
108 | 111 |
|
@@ -155,8 +158,8 @@ static char *ngx_http_link_func_ext_req_headers_add_cmd(ngx_conf_t *cf, ngx_comm |
155 | 158 | static char *ngx_http_link_func_init_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
156 | 159 | #if (nginx_version > 1013003) |
157 | 160 | static char *ngx_http_link_func_subrequest_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
158 | | -static ngx_int_t ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc); |
159 | | -static ngx_int_t ngx_http_link_func_subreqest_sequential_done(ngx_http_request_t *r, void *data, ngx_int_t rc); |
| 161 | +// static ngx_int_t ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc); |
| 162 | +static ngx_int_t ngx_http_link_func_subreqest_done(ngx_http_request_t *r, void *data, ngx_int_t rc); |
160 | 163 | static ngx_int_t ngx_http_link_func_process_subrequest(ngx_http_request_t *r, ngx_http_link_func_subreq_conf_t *subreq, ngx_http_link_func_internal_ctx_t *ctx); |
161 | 164 | #endif |
162 | 165 | static ngx_int_t ngx_http_link_func_content_handler(ngx_http_request_t *r); |
@@ -542,34 +545,47 @@ ngx_http_link_func_subrequest_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf |
542 | 545 | for (i = 1; i < cf->args->nelts; i++) { |
543 | 546 | if (i == 1) { |
544 | 547 | subreq->uri = values[i]; |
545 | | - } else if (i == 2) { |
| 548 | + } else { |
546 | 549 | e = ngx_http_link_func_subrequest_flags; |
547 | 550 | for (j = 0; e[j].name.len != 0; j++) { |
548 | 551 | if (e[j].name.len == values[i].len |
549 | 552 | && ngx_strcasecmp(e[j].name.data, values[i].data) == 0) { |
550 | | - subreq->flag = e[j].value; |
551 | | -// #if(nginx_version < 1013010) |
552 | | -#if(NGX_THREADS) |
553 | | - if (subreq->flag == NGX_SUBREQ_PARALLEL) { |
554 | | - return "parallel request is not applicable in aio threads yet."; |
| 553 | + // subreq->flag = e[j].value; |
| 554 | +// #if(NGX_THREADS) |
| 555 | +// if (subreq->flag == NGX_SUBREQ_PARALLEL) { |
| 556 | +// return "parallel request is not applicable in aio threads yet."; |
| 557 | +// } |
| 558 | +// #endif |
| 559 | + switch (e[j].value) { |
| 560 | + case NGX_SUBREQ_CHECK_STATUS: |
| 561 | + subreq->check_status = 1; |
| 562 | + break; |
| 563 | + case NGX_SUBREQ_INCL_ARGS: |
| 564 | + subreq->incl_args = 1; |
| 565 | + break; |
| 566 | + case NGX_SUBREQ_INCL_BODY: |
| 567 | + subreq->incl_body = 1; |
| 568 | + break; |
| 569 | + default: |
| 570 | + return "invalid subrequest flag given, either incl_args, incl_body or check_status."; |
555 | 571 | } |
556 | | -#endif |
557 | 572 | break; |
558 | 573 | } |
559 | 574 | } |
560 | 575 |
|
561 | 576 | if (e[j].name.len == 0) { |
562 | | - return "invalid subrequest flag given, either parallel, sequential or sequential_check."; |
| 577 | + return "invalid subrequest flag given, either incl_args, incl_body or check_status."; |
563 | 578 | } |
564 | | - } else if (i == 3) { |
| 579 | + |
| 580 | + } /*else if (i == 3) { |
565 | 581 | if ( (sizeof("on") - 1) == values[i].len && ngx_strcasecmp((u_char*)"on", values[i].data) == 0) { |
566 | 582 | subreq->incl_args = 1; |
567 | 583 | } |
568 | 584 | } else if (i == 4) { |
569 | 585 | if ( (sizeof("on") - 1) == values[i].len && ngx_strcasecmp((u_char*)"on", values[i].data) == 0) { |
570 | 586 | subreq->incl_body = 1; |
571 | 587 | } |
572 | | - } |
| 588 | + }*/ |
573 | 589 | } |
574 | 590 | return NGX_CONF_OK; |
575 | 591 | } |
@@ -1080,20 +1096,20 @@ ngx_http_link_func_after_process(ngx_event_t *ev) { |
1080 | 1096 | #endif |
1081 | 1097 |
|
1082 | 1098 | #if (nginx_version > 1013003) |
| 1099 | +// static ngx_int_t |
| 1100 | +// ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc) { |
| 1101 | +// ngx_http_link_func_internal_ctx_t *ctx = data; |
| 1102 | +// ngx_uint_t status = r->headers_out.status; |
| 1103 | + |
| 1104 | +// ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 1105 | +// "subrequest parallel done:%ui", status); |
| 1106 | +// if (status) { |
| 1107 | +// ctx->subreq_parallel_wait_cnt--; |
| 1108 | +// } |
| 1109 | +// return rc; |
| 1110 | +// } |
1083 | 1111 | static ngx_int_t |
1084 | | -ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc) { |
1085 | | - ngx_http_link_func_internal_ctx_t *ctx = data; |
1086 | | - ngx_uint_t status = r->headers_out.status; |
1087 | | - |
1088 | | - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1089 | | - "subrequest parallel done:%ui", status); |
1090 | | - if (status) { |
1091 | | - ctx->subreq_parallel_wait_cnt--; |
1092 | | - } |
1093 | | - return rc; |
1094 | | -} |
1095 | | -static ngx_int_t |
1096 | | -ngx_http_link_func_subreqest_sequential_done(ngx_http_request_t *r, void *data, ngx_int_t rc) { |
| 1112 | +ngx_http_link_func_subreqest_done(ngx_http_request_t *r, void *data, ngx_int_t rc) { |
1097 | 1113 | ngx_http_link_func_internal_ctx_t *ctx = data; |
1098 | 1114 | ngx_uint_t status = r->headers_out.status; |
1099 | 1115 |
|
@@ -1135,30 +1151,17 @@ ngx_http_link_func_process_subrequest(ngx_http_request_t *r, ngx_http_link_func_ |
1135 | 1151 | } |
1136 | 1152 | ps->data = ctx; |
1137 | 1153 |
|
1138 | | - switch (subreq->flag) { |
1139 | | - case NGX_SUBREQ_PARALLEL: |
1140 | | - ps->handler = ngx_http_link_func_subreqest_parallel_done; |
1141 | | - ctx->subreq_parallel_wait_cnt++; |
1142 | | - rc = NGX_AGAIN; |
1143 | | - break; |
1144 | | - case NGX_SUBREQ_SEQUENTIAL_CHK: |
1145 | | - ps->handler = ngx_http_link_func_subreqest_sequential_done; |
1146 | | - ctx->subreq_sequential_wait_cnt++; |
| 1154 | + if (subreq->check_status) { |
1147 | 1155 | ctx->status_check = 1; |
1148 | | - rc = NGX_DONE; |
1149 | | - break; |
1150 | | - case NGX_SUBREQ_SEQUENTIAL: |
1151 | | - default: |
1152 | | - ps->handler = ngx_http_link_func_subreqest_sequential_done; |
1153 | | - ctx->subreq_sequential_wait_cnt++; |
1154 | | - rc = NGX_DONE; |
1155 | | - // ps = NULL; |
1156 | | - break; |
1157 | 1156 | } |
1158 | 1157 |
|
| 1158 | + ps->handler = ngx_http_link_func_subreqest_done; |
| 1159 | + ctx->subreq_sequential_wait_cnt++; |
| 1160 | + rc = NGX_DONE; |
| 1161 | + |
1159 | 1162 | ctx->subreq_curr_index++; |
1160 | 1163 |
|
1161 | | - if (ngx_http_subrequest(r, &subreq->uri, args, &sr, ps, NGX_HTTP_SUBREQUEST_IN_MEMORY) == NGX_ERROR) { |
| 1164 | + if (ngx_http_subrequest(r, &subreq->uri, args, &sr, ps, NGX_HTTP_SUBREQUEST_WAITED) == NGX_ERROR) { |
1162 | 1165 | return NGX_ERROR; |
1163 | 1166 | } |
1164 | 1167 |
|
@@ -1203,7 +1206,7 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) { |
1203 | 1206 |
|
1204 | 1207 | #if (nginx_version > 1013003) |
1205 | 1208 | ngx_int_t rc; |
1206 | | - ngx_uint_t i, n_sub_reqs; |
| 1209 | + ngx_uint_t i;//, n_sub_reqs; |
1207 | 1210 | ngx_http_link_func_subreq_conf_t *subreqs, *subreq; |
1208 | 1211 |
|
1209 | 1212 | if (lcf->_handler == NULL && lcf->subrequests == NULL) { |
@@ -1237,25 +1240,26 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) { |
1237 | 1240 | } |
1238 | 1241 |
|
1239 | 1242 |
|
1240 | | - n_sub_reqs = lcf->subrequests->nelts; |
| 1243 | + // n_sub_reqs = lcf->subrequests->nelts; |
| 1244 | + i = internal_ctx->subreq_curr_index; |
1241 | 1245 | subreqs = lcf->subrequests->elts; |
1242 | 1246 |
|
1243 | | - for (i = internal_ctx->subreq_curr_index; i < n_sub_reqs; i++) { |
| 1247 | + if (i < lcf->subrequests->nelts) { |
1244 | 1248 | subreq = subreqs + i; |
1245 | 1249 | if ( (rc = ngx_http_link_func_process_subrequest(r, subreq, internal_ctx)) == NGX_ERROR ) { |
1246 | 1250 | return NGX_ERROR; |
1247 | 1251 | } |
1248 | 1252 |
|
1249 | | - if (rc == NGX_AGAIN) { |
1250 | | - continue; |
1251 | | - } |
| 1253 | + // if (rc == NGX_AGAIN) { |
| 1254 | + // continue; |
| 1255 | + // } |
1252 | 1256 |
|
1253 | 1257 | return rc; /*NGX_DONE*/ |
1254 | 1258 | } |
1255 | 1259 |
|
1256 | | - if (internal_ctx->subreq_parallel_wait_cnt) { |
1257 | | - return NGX_DONE; |
1258 | | - } |
| 1260 | + // if (internal_ctx->subreq_parallel_wait_cnt) { |
| 1261 | + // return NGX_DONE; |
| 1262 | + // } |
1259 | 1263 | } |
1260 | 1264 |
|
1261 | 1265 | if (lcf->_handler == NULL) { |
|
0 commit comments