mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-27 22:15:49 +00:00
Get X-Forwarded-For from Session request
This commit is contained in:
@@ -68,16 +68,6 @@ public:
|
|||||||
beast::IP::Endpoint
|
beast::IP::Endpoint
|
||||||
remoteAddress() = 0;
|
remoteAddress() = 0;
|
||||||
|
|
||||||
/** Returns the user name if behind a proxy (secure_gateway). */
|
|
||||||
virtual
|
|
||||||
std::string
|
|
||||||
user() = 0;
|
|
||||||
|
|
||||||
/** Returns X-Forwarded-For if behind a proxy (secure_gateway). */
|
|
||||||
virtual
|
|
||||||
std::string
|
|
||||||
forwarded_for() = 0;
|
|
||||||
|
|
||||||
/** Returns the current HTTP request. */
|
/** Returns the current HTTP request. */
|
||||||
virtual
|
virtual
|
||||||
beast::http::message&
|
beast::http::message&
|
||||||
|
|||||||
@@ -86,8 +86,6 @@ protected:
|
|||||||
boost::asio::io_service::strand strand_;
|
boost::asio::io_service::strand strand_;
|
||||||
waitable_timer timer_;
|
waitable_timer timer_;
|
||||||
endpoint_type remote_address_;
|
endpoint_type remote_address_;
|
||||||
std::string forwarded_for_;
|
|
||||||
std::string user_;
|
|
||||||
beast::Journal journal_;
|
beast::Journal journal_;
|
||||||
|
|
||||||
std::string id_;
|
std::string id_;
|
||||||
@@ -183,18 +181,6 @@ protected:
|
|||||||
return beast::IPAddressConversion::from_asio(remote_address_);
|
return beast::IPAddressConversion::from_asio(remote_address_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
|
||||||
user() override
|
|
||||||
{
|
|
||||||
return user_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string
|
|
||||||
forwarded_for() override
|
|
||||||
{
|
|
||||||
return forwarded_for_;
|
|
||||||
}
|
|
||||||
|
|
||||||
beast::http::message&
|
beast::http::message&
|
||||||
request() override
|
request() override
|
||||||
{
|
{
|
||||||
@@ -385,20 +371,9 @@ Peer<Impl>::do_read (yield_context yield)
|
|||||||
if (! ec)
|
if (! ec)
|
||||||
{
|
{
|
||||||
if (parser.complete())
|
if (parser.complete())
|
||||||
{
|
|
||||||
auto const iter = message_.headers.find ("X-Forwarded-For");
|
|
||||||
if (iter != message_.headers.end())
|
|
||||||
forwarded_for_ = iter->second;
|
|
||||||
auto const iter2 = message_.headers.find ("X-User");
|
|
||||||
if (iter2 != message_.headers.end())
|
|
||||||
user_ = iter2->second;
|
|
||||||
|
|
||||||
return do_request();
|
return do_request();
|
||||||
}
|
if (eof)
|
||||||
else if (eof)
|
|
||||||
{
|
|
||||||
ec = boost::asio::error::eof; // incomplete request
|
ec = boost::asio::error::eof; // incomplete request
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ec)
|
if (ec)
|
||||||
|
|||||||
@@ -205,7 +205,24 @@ ServerHandlerImp::processSession (std::shared_ptr<HTTP::Session> const& session,
|
|||||||
{
|
{
|
||||||
processRequest (session->port(), to_string (session->body()),
|
processRequest (session->port(), to_string (session->body()),
|
||||||
session->remoteAddress().at_port (0), makeOutput (*session), jobCoro,
|
session->remoteAddress().at_port (0), makeOutput (*session), jobCoro,
|
||||||
session->forwarded_for(), session->user());
|
[&]
|
||||||
|
{
|
||||||
|
auto const iter =
|
||||||
|
session->request().headers.find(
|
||||||
|
"X-Forwarded-For");
|
||||||
|
if(iter != session->request().headers.end())
|
||||||
|
return iter->second;
|
||||||
|
return std::string{};
|
||||||
|
}(),
|
||||||
|
[&]
|
||||||
|
{
|
||||||
|
auto const iter =
|
||||||
|
session->request().headers.find(
|
||||||
|
"X-User");
|
||||||
|
if(iter != session->request().headers.end())
|
||||||
|
return iter->second;
|
||||||
|
return std::string{};
|
||||||
|
}());
|
||||||
|
|
||||||
if (session->request().keep_alive())
|
if (session->request().keep_alive())
|
||||||
session->complete();
|
session->complete();
|
||||||
|
|||||||
Reference in New Issue
Block a user