HttpReader: fix keep-alive flag.

This commit is contained in:
levlam 2022-11-22 15:46:53 +03:00
parent 0eefb331f8
commit b7e4d567c7

View File

@ -555,8 +555,6 @@ void HttpReader::process_header(MutableSlice header_name, MutableSlice header_va
to_lower_inplace(header_name);
LOG(DEBUG) << "Process header [" << header_name << "=>" << header_value << "]";
query_->headers_.emplace_back(header_name, header_value);
// TODO: check if protocol is HTTP/1.1
query_->keep_alive_ = true;
if (header_name == "content-length") {
auto content_length = to_integer<uint64>(header_value);
if (content_length > MAX_CONTENT_SIZE) {
@ -567,6 +565,8 @@ void HttpReader::process_header(MutableSlice header_name, MutableSlice header_va
to_lower_inplace(header_value);
if (header_value == "close") {
query_->keep_alive_ = false;
} else {
query_->keep_alive_ = true;
}
} else if (header_name == "content-type") {
content_type_ = header_value;
@ -706,8 +706,12 @@ Status HttpReader::parse_head(MutableSlice head) {
} else if (type == "POST") {
query_->type_ = HttpQuery::Type::Post;
} else if (type.size() >= 4 && type.substr(0, 4) == "HTTP") {
if (type == "HTTP/1.1" || type == "HTTP/1.0") {
if (type == "HTTP/1.1") {
query_->type_ = HttpQuery::Type::Response;
query_->keep_alive_ = true;
} else if (type == "HTTP/1.0") {
query_->type_ = HttpQuery::Type::Response;
query_->keep_alive_ = false;
} else {
LOG(INFO) << "Unsupported HTTP version: " << type;
return Status::Error(505, "HTTP Version Not Supported");
@ -748,7 +752,6 @@ Status HttpReader::parse_head(MutableSlice head) {
transfer_encoding_ = Slice();
content_encoding_ = Slice();
query_->keep_alive_ = false;
query_->headers_.clear();
query_->files_.clear();
query_->content_ = MutableSlice();