@@ -121,6 +121,7 @@ static void * ngx_http_c_func_create_loc_conf(ngx_conf_t *cf);
121
121
static char * ngx_http_c_func_merge_loc_conf (ngx_conf_t * cf , void * parent , void * child );
122
122
static char * ngx_http_c_func_ext_req_headers_add_cmd (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
123
123
static char * ngx_http_c_func_init_method (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
124
+ static ngx_int_t ngx_http_c_func_content_handler (ngx_http_request_t * r );
124
125
static ngx_int_t ngx_http_c_func_precontent_handler (ngx_http_request_t * r );
125
126
static void ngx_http_c_func_parse_ext_request_headers (ngx_http_request_t * r , ngx_array_t * ext_req_headers );
126
127
static ngx_int_t ngx_http_c_func_rewrite_handler (ngx_http_request_t * r );
@@ -134,11 +135,11 @@ static u_char* ngx_http_c_func_strdup_with_p(ngx_pool_t *pool, const char *src,
134
135
135
136
// static ngx_int_t ngx_http_c_func_get_resp_var(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
136
137
// static void ngx_http_c_func_set_resp_var_with_r(ngx_http_request_t *r, ngx_http_c_func_ctx_t *ctx, const char* resp_content, size_t resp_len);
137
- #if (NGX_THREADS ) && (nginx_version > 1013003 )
138
- static void ngx_http_c_func_output_filter (ngx_http_request_t * r );
139
- #else
138
+ // #if (NGX_THREADS) && (nginx_version > 1013003)
139
+ // static void ngx_http_c_func_output_filter(ngx_http_request_t *r);
140
+ // #else
140
141
static ngx_int_t ngx_http_c_func_output_filter (ngx_http_request_t * r );
141
- #endif
142
+ // #endif
142
143
143
144
#if (NGX_THREADS ) && (nginx_version > 1013003 )
144
145
static void ngx_http_c_func_after_process (ngx_event_t * ev );
@@ -551,29 +552,26 @@ ngx_http_c_func_post_configuration(ngx_conf_t *cf) {
551
552
/***Enable pre content phase for apps concurrent processing request layer, NGX_DONE and wait for finalize request ***/
552
553
#if (NGX_THREADS ) && (nginx_version > 1013003 )
553
554
h = ngx_array_push (& cmcf -> phases [NGX_HTTP_PRECONTENT_PHASE ].handlers );
555
+ if (h == NULL ) {
556
+ return NGX_ERROR ;
557
+ }
558
+ * h = ngx_http_c_func_precontent_handler ;
559
+
560
+ h = ngx_array_push (& cmcf -> phases [NGX_HTTP_CONTENT_PHASE ].handlers );
561
+ if (h == NULL ) {
562
+ return NGX_ERROR ;
563
+ }
564
+ * h = ngx_http_c_func_content_handler ;
554
565
#else
555
- /**Access Phase is the only last phase for multi thread, we need to mimic to trick nginx c function access phase at first to register,
556
- then it will be last to called as it is reverse order
557
- **/
558
566
h = ngx_array_push (& cmcf -> phases [NGX_HTTP_CONTENT_PHASE ].handlers );
559
- // if (h == NULL) {
560
- // return NGX_ERROR;
561
- // }
562
567
563
- // h = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.elts;
564
- // ngx_uint_t i;
565
- // for (i = 0; i < cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts - 1; i++) {
566
- // h[i + 1] = h[i];
567
- // }
568
-
569
- // h[0] = ngx_http_c_func_precontent_handler;
570
- #endif
571
-
572
568
if (h == NULL ) {
573
569
return NGX_ERROR ;
574
570
}
575
571
576
572
* h = ngx_http_c_func_precontent_handler ;
573
+
574
+ #endif
577
575
578
576
}
579
577
@@ -974,18 +972,8 @@ ngx_http_c_func_after_process(ngx_event_t *ev) {
974
972
r -> main -> blocked -- ;
975
973
r -> aio = 0 ;
976
974
977
- if (r -> done ) {
978
- /*
979
- * trigger connection event handler if the subrequest was
980
- * already finalized; this can happen if the handler is used
981
- * for sendfile() in threads
982
- */
983
- c -> write -> handler (c -> write );
984
-
985
- } else {
986
- r -> write_event_handler (r );
987
- ngx_http_run_posted_requests (c );
988
- }
975
+ ngx_http_core_run_phases (r );
976
+ ngx_http_run_posted_requests (c );
989
977
}
990
978
#endif
991
979
@@ -1023,12 +1011,12 @@ ngx_http_c_func_precontent_handler(ngx_http_request_t *r) {
1023
1011
if (internal_ctx -> aio_processing ) {
1024
1012
return NGX_AGAIN ;
1025
1013
} else {
1026
- #if (NGX_THREADS ) && (nginx_version > 1013003 )
1027
- ngx_http_c_func_output_filter (r );
1028
- return NGX_DONE ;
1029
- #else
1030
- return ngx_http_c_func_output_filter ( r ) ;
1031
- #endif
1014
+ // #if (NGX_THREADS) && (nginx_version > 1013003)
1015
+ // ngx_http_c_func_output_filter(r);
1016
+ // return NGX_OK ;
1017
+ // #else
1018
+ return NGX_DECLINED ;
1019
+ // #endif
1032
1020
}
1033
1021
1034
1022
new_task :
@@ -1100,12 +1088,10 @@ ngx_http_c_func_precontent_handler(ngx_http_request_t *r) {
1100
1088
if ((len = ngx_buf_size (b )) == 0 ) {
1101
1089
goto REQUEST_BODY_DONE ;
1102
1090
}
1103
- buf = ngx_palloc (r -> pool , (len + 1 ) );
1104
- ngx_memcpy (buf , b -> pos , len );
1091
+ buf = b -> pos ;
1105
1092
// buf[len] = '\0';
1106
1093
}
1107
1094
/************End REading ****************/
1108
-
1109
1095
REQUEST_BODY_DONE :
1110
1096
if (buf /*If got request body*/ ) {
1111
1097
ngx_log_error (NGX_LOG_DEBUG , r -> connection -> log , 0 , "request_line=%V \n \
@@ -1167,14 +1153,19 @@ ngx_http_c_func_precontent_handler(ngx_http_request_t *r) {
1167
1153
#endif
1168
1154
lcf -> _handler (new_ctx );
1169
1155
#if (NGX_THREADS ) && (nginx_version > 1013003 )
1170
- ngx_http_c_func_output_filter (r );
1171
- return NGX_DONE ;
1156
+ // ngx_http_c_func_output_filter(r);
1157
+ return NGX_DECLINED ;
1172
1158
#else
1173
- return ngx_http_c_func_output_filter (r );
1159
+ return ngx_http_c_func_content_handler (r );
1174
1160
#endif
1175
1161
1176
1162
} /* ngx_http_c_func_precontent_handler */
1177
1163
1164
+ static ngx_int_t
1165
+ ngx_http_c_func_content_handler (ngx_http_request_t * r ) {
1166
+ return ngx_http_c_func_output_filter (r );
1167
+ } /* ngx_http_c_func_content_handler */
1168
+
1178
1169
static void
1179
1170
ngx_http_c_func_parse_ext_request_headers (ngx_http_request_t * r , ngx_array_t * ext_req_headers ) {
1180
1171
ngx_uint_t i , nelts ;
@@ -1267,17 +1258,25 @@ ngx_http_c_func_rewrite_handler(ngx_http_request_t *r) {
1267
1258
/****Reading Body Request ****/
1268
1259
rc = ngx_http_read_client_request_body (r , ngx_http_c_func_client_body_handler );
1269
1260
1270
- if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE ) {
1271
- #if (nginx_version < 1002006 ) || \
1272
- (nginx_version >= 1003000 && nginx_version < 1003009 )
1261
+ if (rc == NGX_ERROR ) {
1262
+ return NGX_ERROR ;
1263
+ }
1264
+
1265
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE ) {
1266
+ #if (nginx_version >= 8011 && nginx_version < 1002006 ) \
1267
+ || (nginx_version >= 1003000 && nginx_version < 1003009 )
1273
1268
r -> main -> count -- ;
1274
1269
#endif
1275
1270
return rc ;
1276
1271
}
1277
1272
1273
+ #if nginx_version >= 8011
1274
+ r -> main -> count -- ;
1275
+ #endif
1276
+
1278
1277
if (rc == NGX_AGAIN ) {
1279
1278
ctx -> waiting_more_body = 1 ;
1280
- return NGX_DONE ;
1279
+ return NGX_AGAIN ;
1281
1280
}
1282
1281
1283
1282
return NGX_DECLINED ;
@@ -1301,14 +1300,12 @@ static void
1301
1300
ngx_http_c_func_client_body_handler (ngx_http_request_t * r ) {
1302
1301
ngx_http_c_func_internal_ctx_t * ctx ;
1303
1302
ctx = ngx_http_get_module_ctx (r , ngx_http_c_func_module );
1304
- ctx -> done = 1 ;
1305
1303
1306
- #if defined(nginx_version ) && nginx_version >= 8011
1307
- r -> main -> count -- ;
1308
- #endif
1309
1304
/* waiting_more_body my rewrite phase handler */
1310
1305
if (ctx -> waiting_more_body ) {
1306
+ ctx -> done = 1 ;
1311
1307
ctx -> waiting_more_body = 0 ;
1308
+ r -> write_event_handler = ngx_http_core_run_phases ;
1312
1309
ngx_http_core_run_phases (r );
1313
1310
}
1314
1311
}
@@ -1754,68 +1751,69 @@ ngx_http_c_func_write_resp(
1754
1751
);
1755
1752
}
1756
1753
1757
- #if (NGX_THREADS ) && (nginx_version > 1013003 )
1758
- static void
1759
- ngx_http_c_func_output_filter (
1760
- ngx_http_request_t * r
1761
- ) {
1762
- ngx_int_t rc ;
1763
- ngx_chain_t out ;
1764
- ngx_http_c_func_internal_ctx_t * internal_ctx ;
1765
- ngx_str_t * resp_content_type , * resp_status_line ;
1766
- ngx_buf_t * b ;
1754
+ // #if (NGX_THREADS) && (nginx_version > 1013003)
1755
+ // static void
1756
+ // ngx_http_c_func_output_filter(
1757
+ // ngx_http_request_t *r
1758
+ // ) {
1759
+ // ngx_int_t rc;
1760
+ // ngx_chain_t out;
1761
+ // ngx_http_c_func_internal_ctx_t *internal_ctx;
1762
+ // ngx_str_t *resp_content_type, *resp_status_line;
1763
+ // ngx_buf_t *b;
1767
1764
1768
- internal_ctx = ngx_http_get_module_ctx (r , ngx_http_c_func_module );
1765
+ // internal_ctx = ngx_http_get_module_ctx(r, ngx_http_c_func_module);
1769
1766
1770
- if (internal_ctx == NULL ) {
1771
- ngx_log_error (NGX_LOG_EMERG , r -> connection -> log , 0 , "Session is not valid" );
1772
- ngx_http_finalize_request (r , NGX_HTTP_INTERNAL_SERVER_ERROR );
1773
- return ;
1774
- }
1767
+ // if (internal_ctx == NULL) {
1768
+ // ngx_log_error(NGX_LOG_EMERG, r->connection->log, 0, "Session is not valid");
1769
+ // ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1770
+ // return;
1771
+ // }
1775
1772
1776
- if (internal_ctx -> rc == NGX_HTTP_INTERNAL_SERVER_ERROR ) {
1777
- ngx_log_error (NGX_LOG_EMERG , r -> connection -> log , 0 , "Apps Internal Server error" );
1778
- ngx_http_finalize_request (r , NGX_HTTP_INTERNAL_SERVER_ERROR );
1779
- return ;
1780
- }
1773
+ // if (internal_ctx->rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
1774
+ // ngx_log_error(NGX_LOG_EMERG, r->connection->log, 0, "Apps Internal Server error");
1775
+ // ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1776
+ // return;
1777
+ // }
1781
1778
1782
- resp_status_line = & internal_ctx -> status_line ;
1783
- resp_content_type = & internal_ctx -> content_type ;
1784
- b = internal_ctx -> resp_content ;
1779
+ // resp_status_line = &internal_ctx->status_line;
1780
+ // resp_content_type = &internal_ctx->content_type;
1781
+ // b = internal_ctx->resp_content;
1785
1782
1786
- r -> headers_out .status = internal_ctx -> status_code ;
1783
+ // r->headers_out.status = internal_ctx->status_code;
1787
1784
1788
- if (resp_status_line -> len ) {
1789
- r -> headers_out .status_line .len = resp_status_line -> len ;
1790
- r -> headers_out .status_line .data = resp_status_line -> data ;
1791
- }
1785
+ // if (resp_status_line->len) {
1786
+ // r->headers_out.status_line.len = resp_status_line->len;
1787
+ // r->headers_out.status_line.data = resp_status_line->data;
1788
+ // }
1792
1789
1793
- /* Set the Content-Type header. */
1794
- r -> headers_out .content_type .len = resp_content_type -> len ;
1795
- r -> headers_out .content_type .data = resp_content_type -> data ;
1790
+ // /* Set the Content-Type header. */
1791
+ // r->headers_out.content_type.len = resp_content_type->len;
1792
+ // r->headers_out.content_type.data = resp_content_type->data;
1796
1793
1797
- /* Get the content length of the body. */
1798
- r -> headers_out .content_length_n = ngx_buf_size (b );
1794
+ // /* Get the content length of the body. */
1795
+ // r->headers_out.content_length_n = ngx_buf_size(b);
1799
1796
1800
- rc = ngx_http_send_header (r ); /* Send the headers */
1801
- if (rc == NGX_ERROR ) {
1802
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "response processing failed." );
1803
- // ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1804
- rc = NGX_HTTP_INTERNAL_SERVER_ERROR ;
1805
- ngx_http_finalize_request (r , NGX_HTTP_INTERNAL_SERVER_ERROR );
1806
- return ;
1797
+ // rc = ngx_http_send_header(r); /* Send the headers */
1798
+ // if (rc == NGX_ERROR) {
1799
+ // ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "response processing failed.");
1800
+ // // ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1801
+ // rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
1802
+ // ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1803
+ // return;
1807
1804
1808
- }
1805
+ // }
1809
1806
1810
- /* Insertion in the buffer chain. */
1811
- out .buf = b ;
1812
- out .next = NULL ; /* just one buffer */
1807
+ // /* Insertion in the buffer chain. */
1808
+ // out.buf = b;
1809
+ // out.next = NULL; /* just one buffer */
1813
1810
1814
- /* Send the body, and return the status code of the output filter chain. */
1815
- ngx_http_finalize_request (r , ngx_http_output_filter (r , & out )); // only using when request client body
1816
- // rc = ngx_http_output_filter(r, &out);
1817
- }
1818
- #else
1811
+ // /* Send the body, and return the status code of the output filter chain. */
1812
+ // // ngx_http_finalize_request(r, ngx_http_output_filter(r, &out)); // only using when request client body
1813
+ // // rc = ngx_http_output_filter(r, &out);
1814
+ // ngx_http_output_filter(r, &out);
1815
+ // }
1816
+ // #else
1819
1817
static ngx_int_t
1820
1818
ngx_http_c_func_output_filter (
1821
1819
ngx_http_request_t * r
@@ -1871,7 +1869,7 @@ ngx_http_c_func_output_filter(
1871
1869
// ngx_http_finalize_request(r, ngx_http_output_filter(r, &out)); // only using when request client body
1872
1870
return ngx_http_output_filter (r , & out );
1873
1871
}
1874
- #endif
1872
+ // #endif
1875
1873
1876
1874
/****Download Feature Support ****/
1877
1875
static int
0 commit comments