Add IP address to Request.
This commit is contained in:
@@ -19,6 +19,13 @@ Connection::Connection(tcp::socket socket, ConnectionPool* pool,
|
||||
|
||||
void Connection::Start() {
|
||||
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_);
|
||||
DoRead();
|
||||
}
|
||||
|
||||
@@ -55,6 +55,14 @@ public:
|
||||
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.
|
||||
bool IsForm() const;
|
||||
|
||||
@@ -73,6 +81,9 @@ private:
|
||||
// The URL regex matched arguments (usually resource ID's).
|
||||
// Used by server only.
|
||||
UrlArgs args_;
|
||||
|
||||
// Client IP address.
|
||||
std::string ip_;
|
||||
};
|
||||
|
||||
using RequestPtr = std::shared_ptr<Request>;
|
||||
|
||||
Reference in New Issue
Block a user