New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose socket ADDR in http #1947
Conversation
Unsure if this is the rigth way, perhaps openssl should inherit IPSocket or TCPSocket instead? [ytti@ytti.fi ~/usr/git/sykemittari]% ./moi response.addr = Socket::Addr(@family="AF_INET", @ip_port=53380, @ip_address="194.100.7.227") response.peeraddr = Socket::Addr(@family="AF_INET", @ip_port=80, @ip_address="62.78.98.162") request.addr = Socket::Addr(@family="AF_INET", @ip_port=40748, @ip_address="127.0.0.1") request.peeraddr = Socket::Addr(@family="AF_INET", @ip_port=1122, @ip_address="127.0.0.1") ^C [130 ytti@ytti.fi ~/usr/git/sykemittari]% cat moi.cr require "http/server" require "http/client" client = HTTP::Client.new("google.com") response = client.get("/") pp response.addr pp response.peeraddr server = HTTP::Server.new(1122) do |request| pp request.addr pp request.peeraddr HTTP::Response.ok "text/plain", "yaya" end server.listen [ytti@ytti.fi ~/usr/git/sykemittari]%
Perhaps more generic solution would be just to expose 'io'. However this still remains OpenSSL as special-case, as it does not expose peeraddr, and it's obviously not nice to do something like So maybe two things for clean solution |
I'm not sure about this, because we are always requesting the We won't expose the socket since I'm not sure Request should expose the |
What is the downside of exposing them? If we just extract the IP, that's up-to 256bits of new data stored? Considering how long headers etc can be, and how much more useful SADDR of request is, than lot of the other data, isn't it justifiable? |
I'm also thinking of doing something like this to retrieve to client's ip info though i was thinking of reading it from headers. |
Any update on this? |
Ping |
We'll eventually do this, but not by adding this info to the Request object |
Unsure if this is the rigth way, perhaps openssl should inherit IPSocket or TCPSocket instead? Dunno how to do specs, as the MemoryIO does not have addrs, and unsure if it's correct place to add them.
Use case for this is so that web framework can easily tell client's IP.
[ytti@ytti.fi ~/usr/git/sykemittari]% ./moi
response.addr = Socket::Addr(@family="AF_INET", @ip_port=53380, @ip_address="194.100.7.227")
response.peeraddr = Socket::Addr(@family="AF_INET", @ip_port=80, @ip_address="62.78.98.162")
request.addr = Socket::Addr(@family="AF_INET", @ip_port=40748, @ip_address="127.0.0.1")
request.peeraddr = Socket::Addr(@family="AF_INET", @ip_port=1122, @ip_address="127.0.0.1")
^C
[130 ytti@ytti.fi ~/usr/git/sykemittari]% cat moi.cr
require "http/server"
require "http/client"
client = HTTP::Client.new("google.com")
response = client.get("/")
pp response.addr
pp response.peeraddr
server = HTTP::Server.new(1122) do |request|
pp request.addr
pp request.peeraddr
HTTP::Response.ok "text/plain", "yaya"
end
server.listen
[ytti@ytti.fi ~/usr/git/sykemittari]%