Skip to content

Commit 859f10d

Browse files
committed
Merge pull request #44 from pex/master
The last two years of community development
2 parents 611c775 + fbafd48 commit 859f10d

16 files changed

+522
-281
lines changed

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--color

Gemfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
source "http://rubygems.org"
2-
1+
source "https://rubygems.org"
32
gemspec

Gemfile.lock

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,88 @@
11
PATH
22
remote: .
33
specs:
4-
rack-reverse-proxy (0.4.1)
4+
rack-reverse-proxy (0.8.1)
55
rack (>= 1.0.0)
6+
rack-proxy (~> 0.5)
67

78
GEM
8-
remote: http://rubygems.org/
9+
remote: https://rubygems.org/
910
specs:
10-
addressable (2.2.6)
11-
crack (0.1.8)
12-
rack (1.3.2)
13-
rack-test (0.5.7)
11+
addressable (2.3.6)
12+
coderay (1.0.9)
13+
crack (0.4.2)
14+
safe_yaml (~> 1.0.0)
15+
diff-lcs (1.2.5)
16+
ffi (1.9.0)
17+
ffi (1.9.0-java)
18+
formatador (0.2.4)
19+
guard (1.8.1)
20+
formatador (>= 0.2.4)
21+
listen (>= 1.0.0)
22+
lumberjack (>= 1.0.2)
23+
pry (>= 0.9.10)
24+
thor (>= 0.14.6)
25+
guard-bundler (1.0.0)
26+
bundler (~> 1.0)
27+
guard (~> 1.1)
28+
guard-rspec (1.2.1)
29+
guard (>= 1.1)
30+
listen (1.2.2)
31+
rb-fsevent (>= 0.9.3)
32+
rb-inotify (>= 0.9)
33+
rb-kqueue (>= 0.2)
34+
lumberjack (1.0.4)
35+
method_source (0.8.1)
36+
pry (0.9.12.2)
37+
coderay (~> 1.0.5)
38+
method_source (~> 0.8)
39+
slop (~> 3.4)
40+
pry (0.9.12.2-java)
41+
coderay (~> 1.0.5)
42+
method_source (~> 0.8)
43+
slop (~> 3.4)
44+
spoon (~> 0.0)
45+
rack (1.4.1)
46+
rack-proxy (0.5.15)
47+
rack
48+
rack-test (0.6.2)
1449
rack (>= 1.0)
15-
rake (0.8.7)
16-
rspec (1.3.2)
17-
webmock (1.5.0)
18-
addressable (>= 2.2.2)
19-
crack (>= 0.1.7)
50+
rake (10.3.2)
51+
rb-fsevent (0.9.3)
52+
rb-inotify (0.9.0)
53+
ffi (>= 0.5.0)
54+
rb-kqueue (0.2.0)
55+
ffi (>= 0.5.0)
56+
rspec (3.1.0)
57+
rspec-core (~> 3.1.0)
58+
rspec-expectations (~> 3.1.0)
59+
rspec-mocks (~> 3.1.0)
60+
rspec-core (3.1.3)
61+
rspec-support (~> 3.1.0)
62+
rspec-expectations (3.1.1)
63+
diff-lcs (>= 1.2.0, < 2.0)
64+
rspec-support (~> 3.1.0)
65+
rspec-mocks (3.1.0)
66+
rspec-support (~> 3.1.0)
67+
rspec-support (3.1.0)
68+
safe_yaml (1.0.3)
69+
slop (3.4.5)
70+
spoon (0.0.4)
71+
ffi
72+
thor (0.18.1)
73+
webmock (1.18.0)
74+
addressable (>= 2.3.6)
75+
crack (>= 0.3.2)
2076

2177
PLATFORMS
78+
java
2279
ruby
2380

2481
DEPENDENCIES
25-
bundler (~> 1.0.15)
82+
guard-bundler
83+
guard-rspec
2684
rack-reverse-proxy!
27-
rack-test (~> 0.5.7)
28-
rake (~> 0.8.7)
29-
rspec (~> 1.3.2)
30-
webmock (~> 1.5.0)
85+
rack-test (~> 0.6)
86+
rake (~> 10.3)
87+
rspec (~> 3.1)
88+
webmock (~> 1.18)

Guardfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
guard :rspec do
5+
watch(%r{^spec/.+_spec\.rb$})
6+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7+
watch('spec/spec_helper.rb') { "spec" }
8+
end

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# A Reverse Proxy for Rack
2+
[![TravisCI](https://secure.travis-ci.org/pex/rack-reverse-proxy.png "Build Status")](http://travis-ci.org/pex/rack-reverse-proxy "Build Status")
3+
4+
This is a simple reverse proxy for Rack that pretty heavily rips off Rack Forwarder. It is not meant for production systems (although it may work), as the webserver fronting your app is generally much better at this sort of thing.
5+
6+
## Installation
7+
The gem is available on gemcutter. Assuming you have a recent version of Rubygems you should just be able to install it via:
8+
9+
```
10+
gem install rack-reverse-proxy
11+
```
12+
13+
For your Gemfile use:
14+
15+
```ruby
16+
gem "rack-reverse-proxy", require: "rack/reverse_proxy"
17+
```
18+
19+
## Usage
20+
Matchers can be a regex or a string. If a regex is used, you can use the subcaptures in your forwarding url by denoting them with a `$`.
21+
22+
Right now if more than one matcher matches any given route, it throws an exception for an ambiguous match. This will probably change later. If no match is found, the call is forwarded to your application.
23+
24+
Below is an example for configuring the middleware:
25+
26+
```ruby
27+
require 'rack/reverse_proxy'
28+
29+
use Rack::ReverseProxy do
30+
# Set :preserve_host to true globally (default is true already)
31+
reverse_proxy_options preserve_host: true
32+
33+
# Forward the path /test* to http://example.com/test*
34+
reverse_proxy '/test', 'http://example.com/'
35+
36+
# Forward the path /foo/* to http://example.com/bar/*
37+
reverse_proxy /^\/foo(\/.*)$/, 'http://example.com/bar$1', username: 'name', password: 'basic_auth_secret'
38+
end
39+
40+
app = proc do |env|
41+
[ 200, {'Content-Type' => 'text/plain'}, "b" ]
42+
end
43+
run app
44+
```
45+
46+
reverse_proxy_options sets global options for all reverse proxies. Available options are:
47+
* `:preserve_host` Set to false to omit Host headers
48+
* `:username` username for basic auth
49+
* `:password` password for basic auth
50+
* `:matching` is a global only option, if set to :first the first matched url will be requested (no ambigous error). Default: :all.
51+
* `:timeout` seconds to timout the requests
52+
53+
## Note on Patches/Pull Requests
54+
* Fork the project.
55+
* Make your feature addition or bug fix.
56+
* Add tests for it. This is important so I don't break it in a
57+
future version unintentionally.
58+
* Commit, do not mess with rakefile, version, or history.
59+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
60+
* Send me a pull request. Bonus points for topic branches.
61+
62+
## Copyright
63+
64+
Copyright (c) 2010 Jon Swope. See LICENSE for details.

README.rdoc

Lines changed: 0 additions & 56 deletions
This file was deleted.

Rakefile

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
11
require 'rubygems'
22
require 'rake'
33
require 'bundler/gem_tasks'
4+
require 'rspec/core/rake_task'
45

5-
require 'spec/rake/spectask'
6-
Spec::Rake::SpecTask.new(:spec) do |spec|
7-
spec.libs << 'lib' << 'spec'
8-
spec.spec_files = FileList['spec/**/*_spec.rb']
9-
end
10-
11-
Spec::Rake::SpecTask.new(:rcov) do |spec|
12-
spec.libs << 'lib' << 'spec'
6+
RSpec::Core::RakeTask.new(:spec) do |spec|
137
spec.pattern = 'spec/**/*_spec.rb'
14-
spec.rcov = true
158
end
169

1710
task :default => :spec
18-
19-
require 'rake/rdoctask'
20-
Rake::RDocTask.new do |rdoc|
21-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
22-
23-
rdoc.rdoc_dir = 'rdoc'
24-
rdoc.title = "rack-reverse-proxy #{version}"
25-
rdoc.rdoc_files.include('README*')
26-
rdoc.rdoc_files.include('lib/**/*.rb')
27-
end

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.4
1+
0.8.1

lib/rack/exception.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Rack
2+
class GenericProxyURI < Exception
3+
attr_reader :url
4+
5+
def intialize(url)
6+
@url = url
7+
end
8+
9+
def to_s
10+
%Q(Your URL "#{@url}" is too generic. Did you mean "http://#{@url}"?)
11+
end
12+
end
13+
14+
class AmbiguousProxyMatch < Exception
15+
attr_reader :path, :matches
16+
def initialize(path, matches)
17+
@path = path
18+
@matches = matches
19+
end
20+
21+
def to_s
22+
%Q(Path "#{path}" matched multiple endpoints: #{formatted_matches})
23+
end
24+
25+
private
26+
27+
def formatted_matches
28+
matches.map {|matcher| matcher.to_s}.join(', ')
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)