Hi,
I just checked in a change, which makes the TcpSocket available in http
responder. The virtual method beginRequest has a new parameter
TcpSocket. To get the peer IP you should override the method. And don't
forget to call the base method.
class IpResponder : public cxxtools::http::Responder
{
std::string peerIp;
public:
explicit IpResponder(cxxtools::http::Service& service)
: cxxtools::http::Responder(service)
{ }
virtual void beginRequest(cxxtools::net::TcpSocket& socket,
std::istream& in, cxxtools::http::Request& request);
virtual void reply(std::ostream&, cxxtools::http::Request& request,
cxxtools::http::Reply& reply);
};
void IpResponder::beginRequest(cxxtools::net::TcpSocket& socket,
std::istream& in, cxxtools::http::Request& request)
{
cxxtools::http::Responder::beginRequest(socket, in, request);
peerIp = socket.getPeerAddr();
}
void IpResponder::reply(std::ostream& out, cxxtools::http::Request&
request, cxxtools::http::Reply& reply)
{
reply.addHeader("Content-Type", "text/html");
out << "<html>\n"
<< " <head>\n"
<< " <title>IP</title>\n"
<< " </head>\n"
<< " <body>\n"
<< " your IP is " << peerIp
<< " </body>\n"
<< "</html>\n";
}
Tommi
Am 23.03.2015 um 11:50 schrieb Gerald Dachs:
Am 2015-03-23 10:28, schrieb Tommi Mäkitalo:
Hi,
cxxtools has a method getPeerAddr() in cxxtoos::net::TcpSocket but
there
is currently no good way to get it in a http responder.
Yes, this getPeerAddr() I had found in the meantime too.
In the responder there is a virtual method beginRequest which gets a
std::istream. It is actually a cxxtools::IOStream, which has a attached
device. The attached device is the tcp connection. With some ugly
casting you can get the tcp connection.
Interesting approach. I will try that, thanks!
It looks like it would be a useful feature, which I should implement.
That would be nice.
I was sure that you would help me.
Gerald
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general