Skip to content

Instantly share code, notes, and snippets.

View kirkchris's full-sized avatar

Chris Kirk kirkchris

  • Netflix
  • Los Angeles, CA
View GitHub Profile
@kirkchris
kirkchris / CloudFrontRemoteIp.rb
Created April 13, 2016 15:20
Rails 4 Middleware which extends RemoteIp to provide the correct IP for distributions which are deployed as origins to CloudFront
# Note: This code changes in rails 5, so make sure we update before then!
# Written by Chris Kirk at Primer (https://goprimer.com)
class CloudFrontRemoteIp < ActionDispatch::RemoteIp
def call(env)
env["action_dispatch.remote_ip"] = CloudFrontGetIp.new(env, self)
@app.call(env)
end
@kirkchris
kirkchris / CloudFrontRemoteIp.rb
Created April 13, 2016 16:03
Rails 4 Middleware which extends RemoteIp to provide the correct IP for distributions which are deployed as origins to CloudFront, only strips IPs from list of AWS CloudFront servers.
# Note: This code changes in rails 5, so make sure we update before then!
# Written by Chris Kirk at Primer (https://goprimer.com)
class CloudFrontRemoteIp < ActionDispatch::RemoteIp
CLOUDFRONT_IP_RANGES = 'public/cloudfront-ip-ranges.json'.freeze
def call(env)
env["action_dispatch.remote_ip"] = CloudFrontGetIp.new(env, self)
@app.call(env)
end