-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a new remote_ip method to get the ip of the client with some f…
…allbacks. Fixes #1000
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Lucky::RemoteIpAddress | ||
# Returns a `String` IP Address of the remote client by | ||
# looking at a few different possible options. | ||
# | ||
# * HTTP_X_FORWARDED_FOR header | ||
# * REMOTE_ADDRESS header | ||
# * Fallback to localhost 127.0.0.1 | ||
def remote_ip : String | ||
request = @context.request | ||
|
||
request.headers["HTTP_X_FORWARDED_FOR"]?.try(&.split(',').first) || | ||
request.remote_address || | ||
"127.0.0.1" | ||
end | ||
end |