2018-12-31 20:04:05 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/net/HttpContentLengthByteFlow.h"
|
|
|
|
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2020-07-22 20:52:00 +02:00
|
|
|
bool HttpContentLengthByteFlow::loop() {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto ready_size = input_->size();
|
|
|
|
if (ready_size > len_) {
|
|
|
|
ready_size = len_;
|
|
|
|
}
|
2018-02-12 11:37:54 +01:00
|
|
|
auto need_size = min(MIN_UPDATE_SIZE, len_);
|
2018-12-31 20:04:05 +01:00
|
|
|
if (ready_size < need_size) {
|
|
|
|
set_need_size(need_size);
|
2020-07-22 20:52:00 +02:00
|
|
|
return false;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
output_.append(input_->cut_head(ready_size));
|
|
|
|
len_ -= ready_size;
|
|
|
|
if (len_ == 0) {
|
2020-07-22 20:52:00 +02:00
|
|
|
finish(Status::OK());
|
|
|
|
return false;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (!is_input_active_) {
|
2020-07-22 20:52:00 +02:00
|
|
|
finish(Status::Error("Unexpected end of stream"));
|
|
|
|
return false;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-07-22 20:52:00 +02:00
|
|
|
return true;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|