crow icon indicating copy to clipboard operation
crow copied to clipboard

Is it possible to get the remote IP in crow::request?

Open sgiurgiu opened this issue 9 years ago • 6 comments

As far as I could tell the information is available in the Adaptors (SocketAdaptor and SSLAdaptor) but it gets lost. Is it possible to somehow make it available?

Thank you.

sgiurgiu avatar Jul 19 '16 12:07 sgiurgiu

the same question

chengjianxi avatar Jan 24 '18 07:01 chengjianxi

the same question

seeliuh avatar Jun 21 '18 09:06 seeliuh

Maybe try to add std::string field in crow::request (e.g. std::string ipAddress) and then set it in http_connection.h:259 with something like:

req.ipAddress = adaptor_.socket_.remote_endpoint().address().to_string();

Didn't test it, just looked into code.

mrozigor avatar Jun 21 '18 10:06 mrozigor

Hi @mrozigor

req.ipAddress = adaptor_.socket_.remote_endpoint().address().to_string();

I tested it and it works except for a typo (I think). This line worked for me (only remove socket_).

req.ipAddress = adaptor_.remote_endpoint().address().to_string();

Do you have any interest to open a pull request for this?

cadubentzen avatar Sep 20 '18 18:09 cadubentzen

Yeah, I want to make some improvements when I'll have some time ;) Try to make PR by the end of this week.

mrozigor avatar Sep 24 '18 07:09 mrozigor

Added in #322. Changes are on my fork, on master branch.

mrozigor avatar Sep 28 '18 19:09 mrozigor