luckyframework / lucky

A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts.
https://luckyframework.org
MIT License
2.59k stars 156 forks source link

Error: undefined method 'address' for Socket::UNIXAddress (compile-time type is Socket::Address+) #1643

Closed bettinson closed 2 years ago

bettinson commented 2 years ago

Describe the bug Type mismatch for Socket::UNIXAddress

To Reproduce ip_address = context.request.remote_address.try(&.address) || "N/A"

from https://luckyframework.org/guides/http-and-routing/http-handlers#remoteiphandler

Screenshots/code

Error: undefined method 'address' for Socket::UNIXAddress (compile-time type is Socket::Address+) 

Fix

ip_address = context.request.remote_address.as(Socket::IPAddress).try(&.address) || "N/A"

Versions (please complete the following information):

jwoertink commented 2 years ago

Yeah, I feel like we should be able to update the handler to better handle this. You shouldn't have to do all the guessing and stuff with it

https://github.com/luckyframework/lucky/blob/08a70e191b6a242cdf972750219dc732e2d5ec16/src/lucky/remote_ip_handler.cr#L10-L32