POST subrequest body doesn't get parent's request body
hi here is my config and code(ngx_http_echo_subrequest.c->ngx_http_echo_parse_subrequest_spec)
location /fp_guess {
echo_subrequest_async POST /sub1 -h 'body';
#echo_subrequest_async POST /sub2;
#echo_subrequest_async POST /sub3;
#echo_subrequest_async POST /sub4;
}
location /sub1 {
proxy_pass http://192.168.19.223:8980/fp_search.php;
}
............................................... ............................................... if (ngx_strncmp("-h", arg->data, arg->len) == 0) { 275 to_write = &h_str; 276 expecting_opt = 0; 277 continue; 278 } 279 } 280 281 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 282 "unknown option for echo_subrequest_async: %V", arg); 283 284 return NGX_ERROR; 285 } 286 287 if (h_str != NULL && h_str->len) { 288 parsed_sr->query_string = &r->args; 289 if (r->request_body == NULL) { 290 return NGX_ERROR; 291 } 292 293 rb = r->request_body; // ????? is wrong? 294 295 } else if (body_str != NULL && body_str->len) { 296 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); 297 298 if (rb == NULL) { 299 return NGX_ERROR; 300 } 301 302 parsed_sr->content_length_n = body_str->len; 303 304 b = ngx_calloc_buf(r->pool); ................................................................................................
rb = r->request_body rb->bufs, rb->buf is 0x0 in this line , but r->request_body is in ngx_http_do_read_client_request_body(), did i miss something or the code is wrong?
@honwel It is your responsibility to read or discard the request body when using ngx_echo.
Basically you need to put the following line before echo_subrequest_async:
echo_read_request_body;
See https://github.com/agentzh/echo-nginx-module#echo_read_request_body for more details.
thanks a lot.