@@ -1234,7 +1234,7 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
12341234
12351235 if ( internal_ctx -> status_code && internal_ctx -> rc == NGX_CONF_UNSET ) {
12361236 // if ( !internal_ctx->subreq_parallel_wait_cnt) {
1237- ngx_http_finalize_request (r , internal_ctx -> status_code );
1237+ ngx_http_finalize_request (r , internal_ctx -> status_code );
12381238 // }
12391239 return NGX_DONE ;
12401240 }
@@ -1260,14 +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 }
12691269#endif
1270- #if (NGX_THREADS )
1270+ #if (NGX_THREADS )
12711271 if (internal_ctx -> rc == NGX_CONF_UNSET ) {
12721272 goto new_task ;
12731273 }
@@ -1301,20 +1301,13 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
13011301 }
13021302
13031303 if (r -> method & (NGX_HTTP_POST | NGX_HTTP_PUT | NGX_HTTP_PATCH )) {
1304-
1305- /************Reading body ***********
1306- *
1307- * Ref:: https://github.com/calio/form-input-nginx-module
1308- *
1309- ****************/
1310- u_char * p , * buf = NULL ;
1311- // u_char *last;
1304+ u_char * p , * buf ;
13121305 ngx_chain_t * cl ;
1313- size_t len ;
1306+ size_t len ;
13141307 ngx_buf_t * b ;
13151308
13161309 if (r -> request_body == NULL || r -> request_body -> bufs == NULL ) {
1317- goto REQUEST_BODY_DONE ;
1310+ goto SKIP_REQUEST_BODY ;
13181311 }
13191312
13201313 if (r -> request_body -> bufs -> next != NULL ) {
@@ -1323,50 +1316,41 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
13231316 b = cl -> buf ;
13241317 if (b -> in_file ) {
13251318 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "insufficient client_body_buffer_size" );
1326- return NGX_HTTP_INTERNAL_SERVER_ERROR ;
1319+ goto SKIP_REQUEST_BODY ;
13271320 }
13281321 len += b -> last - b -> pos ;
13291322 }
13301323 if (len == 0 ) {
1331- goto REQUEST_BODY_DONE ;
1324+ goto SKIP_REQUEST_BODY ;
13321325 }
13331326
13341327 buf = ngx_palloc (r -> pool , (len + 1 ) );
13351328 if (buf == NULL ) {
13361329 ngx_log_error (NGX_LOG_EMERG , r -> connection -> log , 0 , "insufficient memory." );
1337- goto REQUEST_BODY_DONE ;
1330+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
13381331 }
13391332
13401333 p = buf ;
13411334 for (cl = r -> request_body -> bufs ; cl ; cl = cl -> next ) {
13421335 p = ngx_copy (p , cl -> buf -> pos , cl -> buf -> last - cl -> buf -> pos );
13431336 }
13441337 // buf[len] = '\0';
1345-
1338+ new_ctx -> req_body = buf ;
1339+ new_ctx -> req_body_len = len ;
13461340 } else {
13471341 b = r -> request_body -> bufs -> buf ;
1348- if ((len = ngx_buf_size (b )) == 0 ) {
1349- goto REQUEST_BODY_DONE ;
1342+ if ( ! b -> pos || (len = ngx_buf_size (b )) == 0 ) {
1343+ goto SKIP_REQUEST_BODY ;
13501344 }
1351- buf = b -> pos ;
1352- // buf[len] = '\0';
1353- }
1354- /************End REading ****************/
1355- REQUEST_BODY_DONE :
1356- if (buf /*If got request body*/ ) {
1357- ngx_log_error (NGX_LOG_DEBUG , r -> connection -> log , 0 , "request_line=%V \n \
1358- uri is %V\n \
1359- args is %V\n \
1360- extern is %V\n \
1361- unparsed_uri is %V\n \
1362- Size is %zu" , & r -> request_line , & r -> uri , & r -> args , & r -> exten , & r -> unparsed_uri , len );
1363-
1364- new_ctx -> req_body = buf ;
1345+ new_ctx -> req_body = b -> pos ;
13651346 new_ctx -> req_body_len = len ;
1366- } else {
1367- new_ctx -> req_body = NULL ;
1368- new_ctx -> req_body_len = 0 ;
13691347 }
1348+ ngx_log_error (NGX_LOG_DEBUG , r -> connection -> log , 0 , "request_line=%V \n \
1349+ uri is %V\n \
1350+ args is %V\n \
1351+ extern is %V\n \
1352+ unparsed_uri is %V\n \
1353+ body size is %zu" , & r -> request_line , & r -> uri , & r -> args , & r -> exten , & r -> unparsed_uri , len );
13701354 } else { //if (!(r->method & (NGX_HTTP_POST | NGX_HTTP_PUT | NGX_HTTP_PATCH))) {
13711355 if (ngx_http_discard_request_body (r ) != NGX_OK ) {
13721356 return NGX_HTTP_INTERNAL_SERVER_ERROR ;
@@ -1377,9 +1361,8 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
13771361 args is %V\n \
13781362 extern is %V\n \
13791363 unparsed_uri is %V\n" , & r -> request_line , & r -> uri , & r -> args , & r -> exten , & r -> unparsed_uri );
1380- new_ctx -> req_body = NULL ;
1381- new_ctx -> req_body_len = 0 ;
13821364 }
1365+ SKIP_REQUEST_BODY :
13831366
13841367#if (NGX_THREADS ) && (nginx_version > 1013003 )
13851368 internal_ctx -> aio_processing = 1 ;
@@ -1405,7 +1388,7 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
14051388 return NGX_ERROR ;
14061389 }
14071390 r -> main -> blocked ++ ;
1408- r -> aio = 1 ;
1391+ r -> aio = 1 ;
14091392 // Force to run core run phase to avoid write handler is empty handler
14101393 r -> write_event_handler = ngx_http_core_run_phases ;
14111394 return NGX_DONE ;
0 commit comments