Clean up logging, anti-multiplexing checks
This commit is contained in:
@@ -19,7 +19,7 @@ FastCGIConn::FastCGIConn(int sock, const sockaddr_in6& client_addr, const std::f
|
|||||||
|
|
||||||
FastCGIConn::~FastCGIConn() {
|
FastCGIConn::~FastCGIConn() {
|
||||||
PCHECK(close(sock_) == 0);
|
PCHECK(close(sock_) == 0);
|
||||||
LOG(INFO) << "connection closed";
|
LOG(INFO) << "connection closed (handled " << requests_ << " requests)";
|
||||||
}
|
}
|
||||||
|
|
||||||
void FastCGIConn::Write(const std::vector<iovec>& vecs) {
|
void FastCGIConn::Write(const std::vector<iovec>& vecs) {
|
||||||
@@ -34,7 +34,6 @@ void FastCGIConn::Serve() {
|
|||||||
while (true) {
|
while (true) {
|
||||||
const auto *header = buf_.ReadObj<FastCGIHeader>();
|
const auto *header = buf_.ReadObj<FastCGIHeader>();
|
||||||
if (!header) {
|
if (!header) {
|
||||||
LOG(INFO) << "readobj failed";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +55,7 @@ void FastCGIConn::Serve() {
|
|||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
|
CHECK_EQ(header->RequestId(), request_->RequestId());
|
||||||
ConstBuffer param_buf(buf_.Read(header->ContentLength()), header->ContentLength());
|
ConstBuffer param_buf(buf_.Read(header->ContentLength()), header->ContentLength());
|
||||||
while (param_buf.ReadMaxLen() > 0) {
|
while (param_buf.ReadMaxLen() > 0) {
|
||||||
const auto *param_header = param_buf.ReadObj<FastCGIParamHeader>();
|
const auto *param_header = param_buf.ReadObj<FastCGIParamHeader>();
|
||||||
@@ -68,8 +68,10 @@ void FastCGIConn::Serve() {
|
|||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
{
|
{
|
||||||
|
CHECK_EQ(header->RequestId(), request_->RequestId());
|
||||||
if (header->ContentLength() == 0) {
|
if (header->ContentLength() == 0) {
|
||||||
// Magic signal for completed request (mirrors the HTTP/1.1 protocol)
|
// Magic signal for completed request (mirrors the HTTP/1.1 protocol)
|
||||||
|
requests_++;
|
||||||
callback_(std::move(request_));
|
callback_(std::move(request_));
|
||||||
} else {
|
} else {
|
||||||
std::string_view in(buf_.Read(header->ContentLength()), header->ContentLength());
|
std::string_view in(buf_.Read(header->ContentLength()), header->ContentLength());
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ class FastCGIConn {
|
|||||||
const int sock_;
|
const int sock_;
|
||||||
std::function<void(std::unique_ptr<FastCGIRequest>)> callback_;
|
std::function<void(std::unique_ptr<FastCGIRequest>)> callback_;
|
||||||
|
|
||||||
|
uint64_t requests_ = 0;
|
||||||
|
|
||||||
StreamBuffer buf_;
|
StreamBuffer buf_;
|
||||||
|
|
||||||
std::unique_ptr<FastCGIRequest> request_;
|
std::unique_ptr<FastCGIRequest> request_;
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ FastCGIRequest::FastCGIRequest(uint16_t request_id, FastCGIConn* conn)
|
|||||||
conn_(conn),
|
conn_(conn),
|
||||||
out_buf_(fastcgi_max_record_len) {}
|
out_buf_(fastcgi_max_record_len) {}
|
||||||
|
|
||||||
|
uint16_t FastCGIRequest::RequestId() {
|
||||||
|
return request_id_;
|
||||||
|
}
|
||||||
|
|
||||||
void FastCGIRequest::AddParam(const std::string_view& key, const std::string_view& value) {
|
void FastCGIRequest::AddParam(const std::string_view& key, const std::string_view& value) {
|
||||||
params_.try_emplace(std::string(key), std::string(value));
|
params_.try_emplace(std::string(key), std::string(value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ class FastCGIRequest {
|
|||||||
public:
|
public:
|
||||||
FastCGIRequest(uint16_t request_id, FastCGIConn *conn);
|
FastCGIRequest(uint16_t request_id, FastCGIConn *conn);
|
||||||
|
|
||||||
|
uint16_t RequestId();
|
||||||
|
|
||||||
void AddParam(const std::string_view& key, const std::string_view& value);
|
void AddParam(const std::string_view& key, const std::string_view& value);
|
||||||
void AddIn(const std::string_view& in);
|
void AddIn(const std::string_view& in);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user