HttpReader: open temp file only in FormDataParseState::ReadFile state.
This commit is contained in:
parent
a7952f3836
commit
c2f540edf3
@ -174,8 +174,8 @@ Result<size_t> HttpReader::read_next(HttpQuery *query, bool can_be_slow) {
|
|||||||
}
|
}
|
||||||
// save content to a file
|
// save content to a file
|
||||||
if (temp_file_.empty()) {
|
if (temp_file_.empty()) {
|
||||||
auto file = open_temp_file("file");
|
auto open_status = open_temp_file("file");
|
||||||
if (file.is_error()) {
|
if (open_status.is_error()) {
|
||||||
return Status::Error(500, "Internal Server Error: can't create temporary file");
|
return Status::Error(500, "Internal Server Error: can't create temporary file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,10 +408,6 @@ Result<bool> HttpReader::parse_multipart_form_data(bool can_be_slow) {
|
|||||||
if (query_->files_.size() == max_files_) {
|
if (query_->files_.size() == max_files_) {
|
||||||
return Status::Error(413, "Request Entity Too Large: too many files attached");
|
return Status::Error(413, "Request Entity Too Large: too many files attached");
|
||||||
}
|
}
|
||||||
auto file = open_temp_file(file_name_);
|
|
||||||
if (file.is_error()) {
|
|
||||||
return Status::Error(500, "Internal Server Error: can't create temporary file");
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't need to save headers for files
|
// don't need to save headers for files
|
||||||
file_field_name_ = field_name_.str();
|
file_field_name_ = field_name_.str();
|
||||||
@ -467,6 +463,12 @@ Result<bool> HttpReader::parse_multipart_form_data(bool can_be_slow) {
|
|||||||
if (!can_be_slow) {
|
if (!can_be_slow) {
|
||||||
return Status::Error("SLOW");
|
return Status::Error("SLOW");
|
||||||
}
|
}
|
||||||
|
if (temp_file_.empty()) {
|
||||||
|
auto open_status = open_temp_file(file_name_);
|
||||||
|
if (open_status.is_error()) {
|
||||||
|
return Status::Error(500, "Internal Server Error: can't create temporary file");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (find_boundary(content_->clone(), boundary_, form_data_read_length_)) {
|
if (find_boundary(content_->clone(), boundary_, form_data_read_length_)) {
|
||||||
auto file_part = content_->cut_head(form_data_read_length_).move_as_buffer_slice();
|
auto file_part = content_->cut_head(form_data_read_length_).move_as_buffer_slice();
|
||||||
content_->advance(boundary_.size());
|
content_->advance(boundary_.size());
|
||||||
|
Loading…
Reference in New Issue
Block a user