@@ -511,23 +511,19 @@ const std::shared_ptr<http_response> webserver::internal_error_page(details::mod
511
511
}
512
512
}
513
513
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 (
525
515
MHD_Connection* connection,
526
516
struct details ::modded_request* mr
527
517
)
528
518
{
529
519
mr->second = true ;
530
520
mr->dhr = new http_request (connection, unescaper);
521
+
522
+ if (!mr->has_body )
523
+ {
524
+ return MHD_YES;
525
+ }
526
+
531
527
mr->dhr ->set_content_size_limit (content_size_limit);
532
528
const char *encoding = MHD_lookup_connection_value (
533
529
connection,
@@ -567,20 +563,25 @@ int webserver::bodyfull_requests_answer_first_step(
567
563
return MHD_YES;
568
564
}
569
565
570
- int webserver::bodyfull_requests_answer_second_step (
566
+ int webserver::requests_answer_second_step (
571
567
MHD_Connection* connection, const char * method,
572
568
const char * version, const char * upload_data,
573
569
size_t * upload_data_size, struct details ::modded_request* mr
574
570
)
575
571
{
576
572
if (0 == *upload_data_size) return complete_request (connection, mr, version, method);
577
573
574
+ if (mr->has_body )
575
+ {
576
+
578
577
#ifdef DEBUG
579
- cout << " Writing content: " << upload_data << endl;
578
+ cout << " Writing content: " << upload_data << endl;
580
579
#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
+ }
582
584
583
- if (mr->pp != NULL ) MHD_post_process (mr->pp , upload_data, *upload_data_size);
584
585
*upload_data_size = 0 ;
585
586
return MHD_YES;
586
587
}
@@ -750,7 +751,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
750
751
if (mr->second != false )
751
752
{
752
753
return static_cast <webserver*>(cls)->
753
- bodyfull_requests_answer_second_step (
754
+ requests_answer_second_step (
754
755
connection,
755
756
method,
756
757
version,
@@ -776,7 +777,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
776
777
base_unescaper (t_url, static_cast <webserver*>(cls)->unescaper );
777
778
mr->standardized_url = new string (http_utils::standardize_url (t_url));
778
779
779
- bool body = false ;
780
+ mr-> has_body = false ;
780
781
781
782
access_log (
782
783
static_cast <webserver*>(cls),
@@ -790,22 +791,22 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
790
791
else if (0 == strcmp (method, http_utils::http_method_post.c_str ()))
791
792
{
792
793
mr->callback = &http_resource::render_POST;
793
- body = true ;
794
+ mr-> has_body = true ;
794
795
}
795
796
else if (0 == strcasecmp (method, http_utils::http_method_put.c_str ()))
796
797
{
797
798
mr->callback = &http_resource::render_PUT;
798
- body = true ;
799
+ mr-> has_body = true ;
799
800
}
800
801
else if (0 == strcasecmp (method,http_utils::http_method_delete.c_str ()))
801
802
{
802
803
mr->callback = &http_resource::render_DELETE;
803
- body = true ;
804
+ mr-> has_body = true ;
804
805
}
805
806
else if (0 == strcasecmp (method, http_utils::http_method_patch.c_str ()))
806
807
{
807
808
mr->callback = &http_resource::render_PATCH;
808
- body = true ;
809
+ mr-> has_body = true ;
809
810
}
810
811
else if (0 == strcasecmp (method, http_utils::http_method_head.c_str ()))
811
812
{
@@ -824,7 +825,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
824
825
mr->callback = &http_resource::render_OPTIONS;
825
826
}
826
827
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);
828
829
}
829
830
830
831
};
0 commit comments