Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a possibility that request.remote_ip can return nil?

Are there any instances that request.remote_ip or request.ip can return nil?

like image 304
MoMo Avatar asked Jan 29 '13 07:01

MoMo


1 Answers

According to the rails source it looks like the remote_ip is obtained from 3 separate headers, HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, and REMOTE_ADDR. So, if you're concerned that you might receive a request that has none of those headers, then it looks like it's possible for remote_ip to be nil (looks pretty much the same way in the rack implementation of ip). From what I've read it's pretty safe to assume the REMOTE_ADDR header will be present in most HTTP requests, so it's unlikely either of those values will be nil.

like image 88
siannopollo Avatar answered Nov 15 '22 04:11

siannopollo