@@ -511,23 +511,19 @@ const std::shared_ptr<http_response> webserver::internal_error_page(details::mod
511511 }
512512}
513513
514- int webserver::bodyless_requests_answer (
515- MHD_Connection* connection, const char * method,
516- const char * version, struct details ::modded_request* mr
517- )
518- {
519- http_request req (connection, unescaper);
520- mr->dhr = &(req);
521- return complete_request (connection, mr, version, method);
522- }
523-
524- int webserver::bodyfull_requests_answer_first_step (
514+ int webserver::requests_answer_first_step (
525515 MHD_Connection* connection,
526516 struct details ::modded_request* mr
527517)
528518{
529519 mr->second = true ;
530520 mr->dhr = new http_request (connection, unescaper);
521+
522+ if (!mr->has_body )
523+ {
524+ return MHD_YES;
525+ }
526+
531527 mr->dhr ->set_content_size_limit (content_size_limit);
532528 const char *encoding = MHD_lookup_connection_value (
533529 connection,
@@ -567,20 +563,25 @@ int webserver::bodyfull_requests_answer_first_step(
567563 return MHD_YES;
568564}
569565
570- int webserver::bodyfull_requests_answer_second_step (
566+ int webserver::requests_answer_second_step (
571567 MHD_Connection* connection, const char * method,
572568 const char * version, const char * upload_data,
573569 size_t * upload_data_size, struct details ::modded_request* mr
574570)
575571{
576572 if (0 == *upload_data_size) return complete_request (connection, mr, version, method);
577573
574+ if (mr->has_body )
575+ {
576+
578577#ifdef DEBUG
579- cout << " Writing content: " << upload_data << endl;
578+ cout << " Writing content: " << upload_data << endl;
580579#endif // DEBUG
581- mr->dhr ->grow_content (upload_data, *upload_data_size);
580+ mr->dhr ->grow_content (upload_data, *upload_data_size);
581+
582+ if (mr->pp != NULL ) MHD_post_process (mr->pp , upload_data, *upload_data_size);
583+ }
582584
583- if (mr->pp != NULL ) MHD_post_process (mr->pp , upload_data, *upload_data_size);
584585 *upload_data_size = 0 ;
585586 return MHD_YES;
586587}
@@ -750,7 +751,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
750751 if (mr->second != false )
751752 {
752753 return static_cast <webserver*>(cls)->
753- bodyfull_requests_answer_second_step (
754+ requests_answer_second_step (
754755 connection,
755756 method,
756757 version,
@@ -776,7 +777,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
776777 base_unescaper (t_url, static_cast <webserver*>(cls)->unescaper );
777778 mr->standardized_url = new string (http_utils::standardize_url (t_url));
778779
779- bool body = false ;
780+ mr-> has_body = false ;
780781
781782 access_log (
782783 static_cast <webserver*>(cls),
@@ -790,22 +791,22 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
790791 else if (0 == strcmp (method, http_utils::http_method_post.c_str ()))
791792 {
792793 mr->callback = &http_resource::render_POST;
793- body = true ;
794+ mr-> has_body = true ;
794795 }
795796 else if (0 == strcasecmp (method, http_utils::http_method_put.c_str ()))
796797 {
797798 mr->callback = &http_resource::render_PUT;
798- body = true ;
799+ mr-> has_body = true ;
799800 }
800801 else if (0 == strcasecmp (method,http_utils::http_method_delete.c_str ()))
801802 {
802803 mr->callback = &http_resource::render_DELETE;
803- body = true ;
804+ mr-> has_body = true ;
804805 }
805806 else if (0 == strcasecmp (method, http_utils::http_method_patch.c_str ()))
806807 {
807808 mr->callback = &http_resource::render_PATCH;
808- body = true ;
809+ mr-> has_body = true ;
809810 }
810811 else if (0 == strcasecmp (method, http_utils::http_method_head.c_str ()))
811812 {
@@ -824,7 +825,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
824825 mr->callback = &http_resource::render_OPTIONS;
825826 }
826827
827- return body ? static_cast <webserver*>(cls)->bodyfull_requests_answer_first_step (connection, mr) : static_cast <webserver*>(cls)-> bodyless_requests_answer (connection, method, version , mr);
828+ return static_cast <webserver*>(cls)->requests_answer_first_step (connection, mr);
828829}
829830
830831};
0 commit comments