Add IP address to Request.

This commit is contained in:
Zhe Ma
2019-10-24 16:07:44 +08:00
parent 897d268377
commit 3423dede5d
2 changed files with 18 additions and 0 deletions
+7
View File
@@ -19,6 +19,13 @@ Connection::Connection(tcp::socket socket, ConnectionPool* pool,
void Connection::Start() { void Connection::Start() {
request_.reset(new Request{}); request_.reset(new Request{});
boost::system::error_code ec;
auto endpoint = socket_.remote_endpoint(ec);
if (!ec) {
request_->set_ip(endpoint.address().to_string());
}
request_parser_.Init(request_.get(), view_matcher_); request_parser_.Init(request_.get(), view_matcher_);
DoRead(); DoRead();
} }
+11
View File
@@ -55,6 +55,14 @@ public:
args_ = args; args_ = args;
} }
const std::string& ip() const {
return ip_;
}
void set_ip(const std::string& ip) {
ip_ = ip;
}
// Check if the body is a multi-part form data. // Check if the body is a multi-part form data.
bool IsForm() const; bool IsForm() const;
@@ -73,6 +81,9 @@ private:
// The URL regex matched arguments (usually resource ID's). // The URL regex matched arguments (usually resource ID's).
// Used by server only. // Used by server only.
UrlArgs args_; UrlArgs args_;
// Client IP address.
std::string ip_;
}; };
using RequestPtr = std::shared_ptr<Request>; using RequestPtr = std::shared_ptr<Request>;