rack-proxy 0.5.18 → 0.6.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.
- checksums.yaml +4 -4
- data/.travis.yml +19 -0
- data/Gemfile.lock +7 -0
- data/README.md +48 -7
- data/lib/rack/proxy.rb +8 -2
- data/rack-proxy.gemspec +1 -0
- data/test/test_helper.rb +2 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93dce27bea8526a5e14b0ebd3265682a657b119a
|
4
|
+
data.tar.gz: 727bccbcece1514a3b447f5b8cca2522695129db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b20e8d141a3d369f2bf32cf93a24d336a850c41c5dd960a300c8dd293f1d867eed389f44345da101675b1750ccf510f6e1d06f6d5bc6dd5ae8e7eccc1e206600
|
7
|
+
data.tar.gz: bf2664fb58d99a8a4fbe0f4f3aaee1dc6fd9726a97ec5ff9c23678f0dc65038a5f0867006ffa2c931cd83dfe2b27ccced449e1d612f3a67203ab60b633fad3d1
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
sudo: false
|
2
|
+
cache: bundler
|
3
|
+
language: ruby
|
4
|
+
before_install:
|
5
|
+
- "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
|
6
|
+
- gem install bundler
|
7
|
+
- gem update bundler
|
8
|
+
script: bundle exec rake test
|
9
|
+
rvm:
|
10
|
+
- 2.0.0
|
11
|
+
- 2.1.5
|
12
|
+
- 2.2.2
|
13
|
+
- 2.2.3
|
14
|
+
- 2.3.0
|
15
|
+
- 2.3.1
|
16
|
+
env:
|
17
|
+
- RAILS_ENV=test RACK_ENV=test
|
18
|
+
notifications:
|
19
|
+
email: false
|
data/Gemfile.lock
CHANGED
@@ -7,10 +7,13 @@ PATH
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
+
power_assert (0.2.6)
|
10
11
|
rack (1.2.1)
|
11
12
|
rack-test (0.5.6)
|
12
13
|
rack (>= 1.0)
|
13
14
|
rake (0.9.2.2)
|
15
|
+
test-unit (3.1.5)
|
16
|
+
power_assert
|
14
17
|
|
15
18
|
PLATFORMS
|
16
19
|
ruby
|
@@ -19,3 +22,7 @@ DEPENDENCIES
|
|
19
22
|
rack-proxy!
|
20
23
|
rack-test
|
21
24
|
rake
|
25
|
+
test-unit
|
26
|
+
|
27
|
+
BUNDLED WITH
|
28
|
+
1.12.4
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
A request/response rewriting HTTP proxy. A Rack app.
|
2
|
-
Subclass `Rack::Proxy` and provide your `rewrite_env` and `rewrite_response` methods.
|
1
|
+
A request/response rewriting HTTP proxy. A Rack app. Subclass `Rack::Proxy` and provide your `rewrite_env` and `rewrite_response` methods.
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
Example
|
4
|
+
-------
|
6
5
|
|
7
6
|
```ruby
|
8
7
|
class Foo < Rack::Proxy
|
@@ -44,12 +43,54 @@ The same can be achieved for *all* requests going through the `Rack::Proxy` inst
|
|
44
43
|
Rack::Proxy.new(ssl_verify_none: true)
|
45
44
|
```
|
46
45
|
|
46
|
+
Using it as a middleware:
|
47
|
+
-------------------------
|
48
|
+
|
49
|
+
Example: Proxying only requests that end with ".php" could be done like this:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'rack/proxy'
|
53
|
+
class RackPhpProxy < Rack::Proxy
|
54
|
+
|
55
|
+
def perform_request(env)
|
56
|
+
request = Rack::Request.new(env)
|
57
|
+
if request.path =~ %r{\.php}
|
58
|
+
env["HTTP_HOST"] = "localhost"
|
59
|
+
env["REQUEST_PATH"] = "/php/#{request.fullpath}"
|
60
|
+
super(env)
|
61
|
+
else
|
62
|
+
@app.call(env)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
To use the middleware, please consider the following:
|
69
|
+
|
70
|
+
1) For Rails we could add a configuration in config/application.rb
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
config.middleware.use RackPhpProxy, {ssl_verify_none: true}
|
74
|
+
```
|
75
|
+
|
76
|
+
2) For Sinatra or any Rack-based application:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
class MyAwesomeSinatra < Sinatra::Base
|
80
|
+
use RackPhpProxy, {ssl_verify_none: true}
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
This will allow to run the other requests through the application and only proxy the requests that match the condition from the middleware.
|
85
|
+
|
47
86
|
See tests for more examples.
|
48
87
|
|
49
|
-
|
88
|
+
WARNING
|
89
|
+
-------
|
50
90
|
|
51
91
|
Doesn't work with fakeweb/webmock. Both libraries monkey-patch net/http code.
|
52
92
|
|
53
|
-
|
93
|
+
Todos
|
94
|
+
-----
|
54
95
|
|
55
|
-
|
96
|
+
- Make the docs up to date with the current use case for this code: everything except streaming which involved a rather ugly monkey patch and only worked in 1.8, but does not work now.
|
data/lib/rack/proxy.rb
CHANGED
@@ -5,7 +5,7 @@ module Rack
|
|
5
5
|
|
6
6
|
# Subclass and bring your own #rewrite_request and #rewrite_response
|
7
7
|
class Proxy
|
8
|
-
VERSION = "0.
|
8
|
+
VERSION = "0.6.0"
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def extract_http_request_headers(env)
|
@@ -39,7 +39,13 @@ module Rack
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# @option opts [String, URI::HTTP] :backend Backend host to proxy requests to
|
42
|
-
def initialize(
|
42
|
+
def initialize(app = nil, opts= {})
|
43
|
+
if app.is_a?(Hash)
|
44
|
+
opts = app
|
45
|
+
@app = nil
|
46
|
+
else
|
47
|
+
@app = app
|
48
|
+
end
|
43
49
|
@streaming = opts.fetch(:streaming, true)
|
44
50
|
@ssl_verify_none = opts.fetch(:ssl_verify_none, false)
|
45
51
|
@backend = URI(opts[:backend]) if opts[:backend]
|
data/rack-proxy.gemspec
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacek Becela
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
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'
|
41
55
|
description: A Rack app that provides request/response rewriting proxy capabilities
|
42
56
|
with streaming.
|
43
57
|
email:
|
@@ -47,6 +61,7 @@ extensions: []
|
|
47
61
|
extra_rdoc_files: []
|
48
62
|
files:
|
49
63
|
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
50
65
|
- Gemfile
|
51
66
|
- Gemfile.lock
|
52
67
|
- LICENSE
|