Skip to content

Commit

Permalink
net: don't accept proxy-connection (trivial)
Browse files Browse the repository at this point in the history
TODO response with http header Proxy-Connection: Close for this case.
  • Loading branch information
Chilledheart committed May 16, 2024
1 parent 8b5934b commit b968423
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
23 changes: 6 additions & 17 deletions src/net/http_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,6 @@ void HttpRequestParser::ProcessHeaders(const quiche::BalsaHeaders& headers) {
if (key == "Connection") {
connection_ = std::string(value);
}
if (key == "Proxy-Connection") {
proxy_connection_ = std::string(value);
}
}
}

Expand Down Expand Up @@ -332,10 +329,8 @@ void HttpRequestParser::OnRequestFirstLineInput(std::string_view /*line_input*/,
}
if (version_input == "HTTP/1.1") {
connection_ = "Keep-Alive";
proxy_connection_ = "Keep-Alive";
} else {
connection_ = "Close";
proxy_connection_ = "Close";
}
}

Expand Down Expand Up @@ -458,15 +453,6 @@ int HttpRequestParser::Parse(std::shared_ptr<IOBuf> buf, bool* ok) {
size_t nparsed;
nparsed = http_parser_execute(parser_, &settings_connect, reinterpret_cast<const char*>(buf->data()), buf->length());
*ok = HTTP_PARSER_ERRNO(parser_) == HPE_OK;
if (*ok) {
if (parser_->http_major == 1 && parser_->http_minor == 1) {
connection_ = "Keep-Alive";
proxy_connection_ = "Keep-Alive";
} else {
connection_ = "Close";
proxy_connection_ = "Close";
}
}
return nparsed;
}

Expand Down Expand Up @@ -512,6 +498,12 @@ int HttpRequestParser::OnReadHttpRequestURL(http_parser* p, const char* buf, siz
}
self->http_is_connect_ = true;
}

if (p->http_major == 1 && p->http_minor == 1) {
self->connection_ = "Keep-Alive";
} else {
self->connection_ = "Close";
}
return 0;
}

Expand Down Expand Up @@ -560,9 +552,6 @@ int HttpRequestParser::OnReadHttpRequestHeaderValue(http_parser* parser, const c
if (self->http_field_ == "Connection") {
self->connection_ = std::string(buf, len);
}
if (self->http_field_ == "Proxy-Connection") {
self->proxy_connection_ = std::string(buf, len);
}
return 0;
}

Expand Down
6 changes: 0 additions & 6 deletions src/net/http_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class HttpRequestParser : public quiche::BalsaVisitorInterface {
uint64_t content_length() const { return content_length_; }
const std::string& content_type() const { return content_type_; }
const std::string& connection() const { return connection_; }
const std::string& proxy_connection() const { return proxy_connection_; }

void ReforgeHttpRequest(std::string* header,
const absl::flat_hash_map<std::string, std::string>* additional_headers = nullptr);
Expand Down Expand Up @@ -106,8 +105,6 @@ class HttpRequestParser : public quiche::BalsaVisitorInterface {
std::string content_type_;
/// copy of connection
std::string connection_;
/// copy of proxy-connection
std::string proxy_connection_;

bool first_byte_processed_ = false;
bool headers_done_ = false;
Expand Down Expand Up @@ -140,7 +137,6 @@ class HttpRequestParser {
uint64_t content_length() const { return content_length_; }
const std::string& content_type() const { return content_type_; }
const std::string& connection() const { return connection_; }
const std::string& proxy_connection() const { return proxy_connection_; }

int status_code() const;

Expand Down Expand Up @@ -176,8 +172,6 @@ class HttpRequestParser {
std::string content_type_;
/// copy of connection
std::string connection_;
/// copy of proxy-connection
std::string proxy_connection_;
};

class HttpResponseParser : public HttpRequestParser {
Expand Down

0 comments on commit b968423

Please sign in to comment.