Skip to content

Commit

Permalink
Do not try to parse empty content in HttpReader.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 585a90f2e0236d56626961edd5f822dc4fcb04a2
  • Loading branch information
levlam committed Jul 19, 2020
1 parent 37fa018 commit 3bc52d5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tdnet/td/net/HttpReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Result<size_t> HttpReader::read_next(HttpQuery *query) {
if (content_encoding_.empty()) {
} else if (content_encoding_ == "gzip" || content_encoding_ == "deflate") {
gzip_flow_ = GzipByteFlow(Gzip::Mode::Decode);
gzip_flow_.set_max_output_size(MAX_FILE_SIZE);
gzip_flow_.set_max_output_size(MAX_CONTENT_SIZE);
*source >> gzip_flow_;
source = &gzip_flow_;
} else {
Expand Down Expand Up @@ -229,9 +229,11 @@ Result<size_t> HttpReader::read_next(HttpQuery *query) {
return need_size;
}
case State::ReadMultipartFormData: {
TRY_RESULT(result, parse_multipart_form_data());
if (result) {
break;
if (!content_->empty()) {
TRY_RESULT(result, parse_multipart_form_data());
if (result) {
break;
}
}
return need_size;
}
Expand All @@ -250,7 +252,8 @@ Result<size_t> HttpReader::read_next(HttpQuery *query) {
// returns false if need more data
Result<bool> HttpReader::parse_multipart_form_data() {
while (true) {
LOG(DEBUG) << "Parsing multipart form data in state " << static_cast<int32>(form_data_parse_state_);
LOG(DEBUG) << "Parsing multipart form data in state " << static_cast<int32>(form_data_parse_state_)
<< " with already read length " << form_data_read_length_;
switch (form_data_parse_state_) {
case FormDataParseState::SkipPrologue:
if (find_boundary(content_->clone(), {boundary_.c_str() + 2, boundary_.size() - 2}, form_data_read_length_)) {
Expand Down

0 comments on commit 3bc52d5

Please sign in to comment.