Expose client IP in a smarter way
Closed this issue · 5 comments
Currently, in order to obtain the client's IP, the user needs to:
a) know that pegasus uses luasocket
b) know that the luasocket client is found at req.client
c) know that the IP can be gotten from a luasocket client with :getpeername()
d) extract the IP from the resulting string
This would be fairly easy to expose as something like req:ip()
.
Hi @skwerlman
I liked your suggestion. Thanks 👍
But I couldn't implement it.
I'm receiving the following result when I call client.getpeername()
:
nil Bad file descriptor
Did you have any idea how to solve it? :)
try client:getpeername()
. client
is an object, and so is expecting itself as the first arg. (note the colon)
It results that output (nil Bad file descriptor
)
Do you have any idea how to solve it?
i'm gonna open a pr; if it gives you issues, let me know.
It's working for me.
When I put in a method, it was not working every time. I couldn't understand the problem =/
I'll add some tests and I'll put in Pegasus core. Thanks, man ;)