add a Request::raw_post buffer
This buffer is used when a Function::NeedToCopyRawPost() method returned true. while here: - remove WINIX_POST_PARAMS and WINIX_RAW_POST_STRING plugin messages
This commit is contained in:
@@ -1293,18 +1293,17 @@ void App::ReadInputPostToBuffer()
|
||||
const int buffer_len = sizeof(buffer) / sizeof(char) - 1;
|
||||
int read_len;
|
||||
|
||||
post_buffer.clear();
|
||||
post_buffer.reserve(1024 * 1024 * 5); // IMPROVEME add to config?
|
||||
cur.request->raw_post.clear();
|
||||
cur.request->raw_post.reserve(1024 * 1024 * 5); // IMPROVEME add to config?
|
||||
|
||||
do
|
||||
{
|
||||
read_len = FCGX_GetStr(buffer, buffer_len, cur.request->fcgi_request.in);
|
||||
|
||||
if( read_len > 0 )
|
||||
post_buffer.write(buffer, read_len);
|
||||
cur.request->raw_post.write(buffer, read_len);
|
||||
}
|
||||
while( read_len == buffer_len );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1317,7 +1316,7 @@ void App::ParsePostJson()
|
||||
space_parser.set_all_items_limit( (fun && fun->post_max_all_items != 0) ? fun->post_max_all_items : config.post_max_all_items);
|
||||
space_parser.set_nested_level_limit( (fun && fun->post_max_nested_objects != 0) ? fun->post_max_nested_objects : config.post_max_nested_objects);
|
||||
|
||||
pt::SpaceParser::Status parse_status = space_parser.parse_json(post_buffer, cur.request->post_in);
|
||||
pt::SpaceParser::Status parse_status = space_parser.parse_json(cur.request->raw_post, cur.request->post_in);
|
||||
|
||||
if( parse_status == pt::SpaceParser::ok )
|
||||
{
|
||||
@@ -1362,13 +1361,13 @@ void App::ParsePostJson()
|
||||
}
|
||||
|
||||
|
||||
void App::ReadPostJson()
|
||||
void App::ReadPostJson(bool copy_raw_post)
|
||||
{
|
||||
ReadInputPostToBuffer();
|
||||
|
||||
if( !post_buffer.empty() )
|
||||
if( !cur.request->raw_post.empty() )
|
||||
{
|
||||
if( config.post_json_max == 0 || post_buffer.size() <= config.post_json_max )
|
||||
if( config.post_json_max == 0 || cur.request->raw_post.size() <= config.post_json_max )
|
||||
{
|
||||
ParsePostJson();
|
||||
}
|
||||
@@ -1378,7 +1377,8 @@ void App::ReadPostJson()
|
||||
cur.request->http_status = Header::status_400_bad_request;
|
||||
}
|
||||
|
||||
post_buffer.clear();
|
||||
if( !copy_raw_post )
|
||||
cur.request->raw_post.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1392,28 +1392,30 @@ void App::ReadPostVars()
|
||||
if( cur.request->method == Request::post || cur.request->method == Request::put ||
|
||||
cur.request->method == Request::patch || cur.request->method == Request::delete_ )
|
||||
{
|
||||
bool copy_raw_post = (cur.request->function && cur.request->function->NeedToCopyRawPost());
|
||||
|
||||
if( pt::is_substr_nc(Header::multipart_form_data, cur.request->env_content_type.c_str()) )
|
||||
{
|
||||
log << log3 << "App: content type: " << Header::multipart_form_data << logend;
|
||||
post_multi_parser.Parse(cur.request->fcgi_request.in, *cur.request); // IMPROVEME add checking for return status
|
||||
post_multi_parser.Parse(cur.request->fcgi_request.in, *cur.request, copy_raw_post); // IMPROVEME add checking for return status
|
||||
}
|
||||
else
|
||||
if( pt::is_substr_nc(Winix::Header::application_json, cur.request->env_content_type.c_str()) )
|
||||
{
|
||||
log << log3 << "App: content type: " << Winix::Header::application_json << ", using json parser" << logend;
|
||||
ReadPostJson();
|
||||
ReadPostJson(copy_raw_post);
|
||||
}
|
||||
else
|
||||
if( pt::is_substr_nc(Header::application_x_www_form_urlencoded, cur.request->env_content_type.c_str()) )
|
||||
{
|
||||
log << log3 << "App: content type: " << Winix::Header::application_x_www_form_urlencoded << logend;
|
||||
post_parser.Parse(cur.request->fcgi_request.in, *cur.request); // IMPROVEME add checking for return status
|
||||
post_parser.Parse(cur.request->fcgi_request.in, *cur.request, copy_raw_post); // IMPROVEME add checking for return status
|
||||
}
|
||||
else
|
||||
if( cur.request->env_content_type.empty() )
|
||||
{
|
||||
log << log2 << "App: Content-Type header is not set or is empty, I try to parse as " << Header::application_x_www_form_urlencoded << logend;
|
||||
post_parser.Parse(cur.request->fcgi_request.in, *cur.request); // IMPROVEME add checking for return status
|
||||
post_parser.Parse(cur.request->fcgi_request.in, *cur.request, copy_raw_post); // IMPROVEME add checking for return status
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user