Migrate to other thread when receiving a file in multipart/form-data.

GitOrigin-RevId: dbd6c1092f297c5b534508f070f49c311a756fe4
This commit is contained in:
levlam 2020-07-24 15:32:33 +03:00
parent 2882e96b63
commit 421ec5fa8f
2 changed files with 6 additions and 3 deletions

View File

@ -247,7 +247,7 @@ Result<size_t> HttpReader::read_next(HttpQuery *query, bool can_be_slow) {
}
case State::ReadMultipartFormData: {
if (!content_->empty()) {
TRY_RESULT(result, parse_multipart_form_data());
TRY_RESULT(result, parse_multipart_form_data(can_be_slow));
if (result) {
break;
}
@ -267,7 +267,7 @@ Result<size_t> HttpReader::read_next(HttpQuery *query, bool can_be_slow) {
// returns Status on wrong request
// returns true if parsing has finished
// returns false if need more data
Result<bool> HttpReader::parse_multipart_form_data() {
Result<bool> HttpReader::parse_multipart_form_data(bool can_be_slow) {
while (true) {
LOG(DEBUG) << "Parsing multipart form data in state " << static_cast<int32>(form_data_parse_state_)
<< " with already read length " << form_data_read_length_;
@ -452,6 +452,9 @@ Result<bool> HttpReader::parse_multipart_form_data() {
}
return false;
case FormDataParseState::ReadFile: {
if (!can_be_slow) {
return Status::Error("SLOW");
}
if (find_boundary(content_->clone(), boundary_, form_data_read_length_)) {
auto file_part = content_->cut_head(form_data_read_length_).move_as_buffer_slice();
content_->advance(boundary_.size());

View File

@ -89,7 +89,7 @@ class HttpReader {
Result<size_t> split_header() TD_WARN_UNUSED_RESULT;
void process_header(MutableSlice header_name, MutableSlice header_value);
Result<bool> parse_multipart_form_data() TD_WARN_UNUSED_RESULT;
Result<bool> parse_multipart_form_data(bool can_be_slow) TD_WARN_UNUSED_RESULT;
Status parse_url(MutableSlice url) TD_WARN_UNUSED_RESULT;
Status parse_parameters(MutableSlice parameters) TD_WARN_UNUSED_RESULT;
Status parse_json_parameters(MutableSlice parameters) TD_WARN_UNUSED_RESULT;