Fail HTTP request reading if unexpected end of data reached.
This commit is contained in:
parent
0d363724e5
commit
511483e12c
@ -43,6 +43,16 @@ Result<size_t> HttpReader::read_next(HttpQuery *query, bool can_be_slow) {
|
|||||||
CHECK(query_ == nullptr);
|
CHECK(query_ == nullptr);
|
||||||
query_ = query;
|
query_ = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto r_size = do_read_next(can_be_slow);
|
||||||
|
if (state_ != State::ReadHeaders && flow_sink_.is_ready() && r_size.is_ok() && r_size.ok() > 0) {
|
||||||
|
CHECK(flow_sink_.status().is_ok());
|
||||||
|
return Status::Error(400, "Bad Request: unexpected end of request content");
|
||||||
|
}
|
||||||
|
return r_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<size_t> HttpReader::do_read_next(bool can_be_slow) {
|
||||||
size_t need_size = input_->size() + 1;
|
size_t need_size = input_->size() + 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (state_ != State::ReadHeaders) {
|
if (state_ != State::ReadHeaders) {
|
||||||
|
@ -87,6 +87,8 @@ class HttpReader {
|
|||||||
string temp_file_name_;
|
string temp_file_name_;
|
||||||
int64 file_size_ = 0;
|
int64 file_size_ = 0;
|
||||||
|
|
||||||
|
Result<size_t> do_read_next(bool can_be_slow);
|
||||||
|
|
||||||
Result<size_t> split_header() TD_WARN_UNUSED_RESULT;
|
Result<size_t> split_header() TD_WARN_UNUSED_RESULT;
|
||||||
void process_header(MutableSlice header_name, MutableSlice header_value);
|
void process_header(MutableSlice header_name, MutableSlice header_value);
|
||||||
Result<bool> parse_multipart_form_data(bool can_be_slow) TD_WARN_UNUSED_RESULT;
|
Result<bool> parse_multipart_form_data(bool can_be_slow) TD_WARN_UNUSED_RESULT;
|
||||||
|
@ -25,6 +25,7 @@ class ByteFlowInterface {
|
|||||||
virtual size_t get_write_size() = 0;
|
virtual size_t get_write_size() = 0;
|
||||||
virtual void reset_need_size() {
|
virtual void reset_need_size() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteFlowInterface() = default;
|
ByteFlowInterface() = default;
|
||||||
ByteFlowInterface(const ByteFlowInterface &) = delete;
|
ByteFlowInterface(const ByteFlowInterface &) = delete;
|
||||||
ByteFlowInterface &operator=(const ByteFlowInterface &) = delete;
|
ByteFlowInterface &operator=(const ByteFlowInterface &) = delete;
|
||||||
@ -139,6 +140,7 @@ class ByteFlowBaseCommon : public ByteFlowInterface {
|
|||||||
bool can_read{true};
|
bool can_read{true};
|
||||||
bool can_write{true};
|
bool can_write{true};
|
||||||
Options options_;
|
Options options_;
|
||||||
|
|
||||||
void finish(Status status) {
|
void finish(Status status) {
|
||||||
stop_flag_ = true;
|
stop_flag_ = true;
|
||||||
need_size_ = 0;
|
need_size_ = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user