rack-cloudflare_ip 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 315f224c4404b2d37056a551ac2e877f453c4b20
4
+ data.tar.gz: 29a5dda0fa0c6fb25ee052fd4cafc69691a1d1a0
5
+ SHA512:
6
+ metadata.gz: 56eca15cc8467c11373db9ab2a94b32f4f14b2a26b6530ac38b480643985caf3e78c44921fbf708c018b80b9bf68aae742c3b20cd5efa8ed0b480231fe56a6c1
7
+ data.tar.gz: 68ba2cf1e49f9576a907f7c91d938b6e9ad94a40f5fb2640ac61abe2babe3614800b54f2926cdda012d19406303cd00edaa4bd011c04046ab0b24f8fcb5170ea
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-cloudflare_ip.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Pip Taylor
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Rack::CloudflareIp
2
+
3
+ Overwrites the `X_FORWARDED_FOR` HTTP header with the contents of
4
+ `CF_CONNECTING_IP` if it's present. This makes `request.remote_ip` in
5
+ Rails return the IP of the user making the request rather than the IP of
6
+ a Cloudflare server.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'rack-cloudflare_ip'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rack-cloudflare_ip
21
+
22
+ ## Usage
23
+
24
+ In `config/application.rb`:
25
+
26
+ ```ruby
27
+ require "rack/cloudflare_ip"
28
+ config.middleware.use Rack::CloudflareIp
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( http://github.com/ms-digital-labs/rack-cloudflare_ip/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ require "rack"
2
+
3
+ module Rack
4
+ class CloudflareIp
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env.has_key?("HTTP_CF_CONNECTING_IP")
11
+ env["HTTP_ORIGINAL_X_FORWARDED_FOR"] = env["HTTP_X_FORWARDED_FOR"]
12
+ env["HTTP_X_FORWARDED_FOR"] = env["HTTP_CF_CONNECTING_IP"]
13
+ end
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rack-cloudflare_ip"
7
+ spec.version = "1.0.0"
8
+ spec.authors = ["Pip Taylor"]
9
+ spec.email = ["pip@evilgeek.co.uk"]
10
+ spec.summary = %q{Set X-Forwarded-For header to original client IP when using Cloudflare in proxy mode}
11
+ spec.homepage = "https://github.com/ms-digital-labs/rack-cloudflare_ip"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "rack"
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rack-test"
25
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::CloudflareIp do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ Rack::CloudflareIp.new(base_app)
8
+ end
9
+
10
+ def base_app
11
+ lambda { |env|
12
+ headers = env.select { |k, _| k =~ /^HTTP_.*/ }
13
+ [200, headers, []]
14
+ }
15
+ end
16
+
17
+ before do
18
+ get "/", nil, headers
19
+ end
20
+
21
+ context "with HTTP_CF_CONNECTING_IP header" do
22
+ let(:headers) { {
23
+ "HTTP_CF_CONNECTING_IP" => "123.123.123.123",
24
+ "HTTP_X_FORWARDED_FOR" => "234.234.234.234"
25
+ } }
26
+
27
+ it "overwrites the HTTP_X_FORWARDED_FOR header" do
28
+ expect(last_response.headers["HTTP_X_FORWARDED_FOR"]).to eq("123.123.123.123")
29
+ end
30
+
31
+ it "saves the original header in HTTP_ORIGINAL_X_FORWARDED_FOR" do
32
+ expect(last_response.headers["HTTP_ORIGINAL_X_FORWARDED_FOR"])
33
+ .to eq("234.234.234.234")
34
+ end
35
+ end
36
+
37
+ context "without HTTP_CF_CONNECTING_IP header" do
38
+ let(:headers) { {
39
+ "HTTP_X_FORWARDED_FOR" => "234.234.234.234"
40
+ } }
41
+
42
+ it "doesn't modify the HTTP_X_FORWARDED_FOR header" do
43
+ expect(last_response.headers["HTTP_X_FORWARDED_FOR"]).to eq("234.234.234.234")
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rack/cloudflare_ip'
3
+ require "rack/test"
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-cloudflare_ip
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Pip Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - pip@evilgeek.co.uk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/rack/cloudflare_ip.rb
98
+ - rack-cloudflare_ip.gemspec
99
+ - spec/rack/cloudflare_ip_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/ms-digital-labs/rack-cloudflare_ip
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Set X-Forwarded-For header to original client IP when using Cloudflare in
125
+ proxy mode
126
+ test_files:
127
+ - spec/rack/cloudflare_ip_spec.rb
128
+ - spec/spec_helper.rb
129
+ has_rdoc: