Class: ActionPack::CloudfrontViewerAddress::RemoteIp
- Inherits:
-
Object
- Object
- ActionPack::CloudfrontViewerAddress::RemoteIp
- Defined in:
- lib/action_pack/cloudfront_viewer_address/remote_ip.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RemoteIp
constructor
A new instance of RemoteIp.
Constructor Details
#initialize(app) ⇒ RemoteIp
Returns a new instance of RemoteIp.
8 9 10 |
# File 'lib/action_pack/cloudfront_viewer_address/remote_ip.rb', line 8 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/action_pack/cloudfront_viewer_address/remote_ip.rb', line 12 def call(env) req = ::ActionDispatch::Request.new(env) if env["HTTP_CLOUDFRONT_VIEWER_ADDRESS"].present? # IPv4 "HTTP_CLOUDFRONT_VIEWER_ADDRESS" = "1.1.1.1:3000" # IPV6 "HTTP_CLOUDFRONT_VIEWER_ADDRESS" = "0000:0000:0000:0000:0000:0000:0000:0000:3000" req.remote_ip = req.env["HTTP_CLOUDFRONT_VIEWER_ADDRESS"].sub(/:\d+\z/, "") # remove `port(:0000)` part end app.call(req.env) end |