Get X-Forwarded-For from Session request

This commit is contained in:
Vinnie Falco
2016-02-02 11:42:55 -05:00
parent de416adadd
commit be71e8afa2
3 changed files with 19 additions and 37 deletions

View File

@@ -68,16 +68,6 @@ public:
beast::IP::Endpoint
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. */
virtual
beast::http::message&

View File

@@ -86,8 +86,6 @@ protected:
boost::asio::io_service::strand strand_;
waitable_timer timer_;
endpoint_type remote_address_;
std::string forwarded_for_;
std::string user_;
beast::Journal journal_;
std::string id_;
@@ -183,18 +181,6 @@ protected:
return beast::IPAddressConversion::from_asio(remote_address_);
}
std::string
user() override
{
return user_;
}
std::string
forwarded_for() override
{
return forwarded_for_;
}
beast::http::message&
request() override
{
@@ -385,20 +371,9 @@ Peer<Impl>::do_read (yield_context yield)
if (! ec)
{
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();
}
else if (eof)
{
if (eof)
ec = boost::asio::error::eof; // incomplete request
}
}
if (ec)

View File

@@ -205,7 +205,24 @@ ServerHandlerImp::processSession (std::shared_ptr<HTTP::Session> const& session,
{
processRequest (session->port(), to_string (session->body()),
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())
session->complete();