@@ -2842,7 +2842,6 @@ class MultipartFormDataParser {
28422842 if (pattern.size () > buf_.size ()) { return true ; }
28432843 auto pos = buf_.find (pattern);
28442844 if (pos != 0 ) {
2845- is_done_ = true ;
28462845 return false ;
28472846 }
28482847 buf_.erase (0 , pattern.size ());
@@ -2862,7 +2861,6 @@ class MultipartFormDataParser {
28622861 if (pos == 0 ) {
28632862 if (!header_callback (file_)) {
28642863 is_valid_ = false ;
2865- is_done_ = false ;
28662864 return false ;
28672865 }
28682866 buf_.erase (0 , crlf_.size ());
@@ -2886,18 +2884,25 @@ class MultipartFormDataParser {
28862884 off_ += pos + crlf_.size ();
28872885 pos = buf_.find (crlf_);
28882886 }
2889- break ;
2887+ if (state_ != 3 ) { return true ; }
28902888 }
28912889 case 3 : { // Body
28922890 {
28932891 auto pattern = crlf_ + dash_;
28942892 if (pattern.size () > buf_.size ()) { return true ; }
28952893
28962894 auto pos = buf_.find (pattern);
2897- if (pos == std::string::npos) { pos = buf_.size (); }
2895+ if (pos == std::string::npos) {
2896+ pos = buf_.size ();
2897+ while (pos > 0 ) {
2898+ auto c = buf_[pos - 1 ];
2899+ if (c != ' \r ' && c != ' \n ' && c != ' -' ) { break ; }
2900+ pos--;
2901+ }
2902+ }
2903+
28982904 if (!content_callback (buf_.data (), pos)) {
28992905 is_valid_ = false ;
2900- is_done_ = false ;
29012906 return false ;
29022907 }
29032908
@@ -2913,7 +2918,6 @@ class MultipartFormDataParser {
29132918 if (pos != std::string::npos) {
29142919 if (!content_callback (buf_.data (), pos)) {
29152920 is_valid_ = false ;
2916- is_done_ = false ;
29172921 return false ;
29182922 }
29192923
@@ -2923,7 +2927,6 @@ class MultipartFormDataParser {
29232927 } else {
29242928 if (!content_callback (buf_.data (), pattern.size ())) {
29252929 is_valid_ = false ;
2926- is_done_ = false ;
29272930 return false ;
29282931 }
29292932
@@ -2948,7 +2951,6 @@ class MultipartFormDataParser {
29482951 is_valid_ = true ;
29492952 state_ = 5 ;
29502953 } else {
2951- is_done_ = true ;
29522954 return true ;
29532955 }
29542956 }
@@ -2976,7 +2978,6 @@ class MultipartFormDataParser {
29762978 std::string buf_;
29772979 size_t state_ = 0 ;
29782980 bool is_valid_ = false ;
2979- bool is_done_ = false ;
29802981 size_t off_ = 0 ;
29812982 MultipartFormData file_;
29822983};
@@ -3978,6 +3979,17 @@ inline bool Server::read_content_core(Stream &strm, Request &req, Response &res,
39783979
39793980 multipart_form_data_parser.set_boundary (std::move (boundary));
39803981 out = [&](const char *buf, size_t n) {
3982+ /* For debug
3983+ size_t pos = 0;
3984+ while (pos < n) {
3985+ auto read_size = std::min<size_t>(1, n - pos);
3986+ auto ret = multipart_form_data_parser.parse(
3987+ buf + pos, read_size, multipart_receiver, mulitpart_header);
3988+ if (!ret) { return false; }
3989+ pos += read_size;
3990+ }
3991+ return true;
3992+ */
39813993 return multipart_form_data_parser.parse (buf, n, multipart_receiver,
39823994 mulitpart_header);
39833995 };
0 commit comments