rack-proxy 0.5.15 → 0.5.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +55 -0
- data/lib/rack/proxy.rb +4 -4
- data/test/rack_proxy_test.rb +10 -0
- metadata +3 -3
- data/Readme +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fc4fb4adfc9abb9d0d4c77a83b04117b64384c6
|
4
|
+
data.tar.gz: c2165351459b4f3eb789c6ec9bb503aaa99d4d5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd02a381c0a39dff1c73b125cd5002715eefb90e82b1286547b14e0fc12a9df659a6c2234031a00441b9d5a31ad1f8aab3e94257e5a256de506f35878abce9d6
|
7
|
+
data.tar.gz: 3ff094bcc6840f908140de6d63bc37453dbfd9c25b689a0a4691e9b7374fee7fc6471fa5b508bfabf92a11dfb399f82110a9135b5c3e480b59a4b61824cd6aef
|
data/Gemfile.lock
CHANGED
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
A request/response rewriting HTTP proxy. A Rack app.
|
2
|
+
Subclass `Rack::Proxy` and provide your `rewrite_env` and `rewrite_response` methods.
|
3
|
+
|
4
|
+
|
5
|
+
## Example
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class Foo < Rack::Proxy
|
9
|
+
|
10
|
+
def rewrite_env(env)
|
11
|
+
env["HTTP_HOST"] = "example.com"
|
12
|
+
|
13
|
+
env
|
14
|
+
end
|
15
|
+
|
16
|
+
def rewrite_response(triplet)
|
17
|
+
status, headers, body = triplet
|
18
|
+
|
19
|
+
headers["X-Foo"] = "Bar"
|
20
|
+
|
21
|
+
triplet
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
### Disable SSL session verification when proxying a server with e.g. self-signed SSL certs
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class TrustingProxy < Rack::Proxy
|
31
|
+
|
32
|
+
def rewrite_env(env)
|
33
|
+
env["rack.ssl_verify_none"] = true
|
34
|
+
|
35
|
+
env
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
The same can be achieved for *all* requests going through the `Rack::Proxy` instance by using
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Rack::Proxy.new(ssl_verify_none: true)
|
45
|
+
```
|
46
|
+
|
47
|
+
See tests for more examples.
|
48
|
+
|
49
|
+
## WARNING
|
50
|
+
|
51
|
+
Doesn't work with fakeweb/webmock. Both libraries monkey-patch net/http code.
|
52
|
+
|
53
|
+
## Todos
|
54
|
+
|
55
|
+
* 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.5.
|
8
|
+
VERSION = "0.5.16"
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def extract_http_request_headers(env)
|
@@ -25,10 +25,10 @@ module Rack
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def normalize_headers(headers)
|
28
|
-
mapped = headers.map do|k, v|
|
28
|
+
mapped = headers.map do |k, v|
|
29
29
|
[k, if v.is_a? Array then v.join("\n") else v end]
|
30
30
|
end
|
31
|
-
Hash[mapped]
|
31
|
+
Utils::HeaderHash.new Hash[mapped]
|
32
32
|
end
|
33
33
|
|
34
34
|
protected
|
@@ -39,7 +39,7 @@ module Rack
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# @option opts [String, URI::HTTP] :backend Backend host to proxy requests to
|
42
|
-
def initialize(opts={})
|
42
|
+
def initialize(opts = {})
|
43
43
|
@streaming = opts.fetch(:streaming, true)
|
44
44
|
@ssl_verify_none = opts.fetch(:ssl_verify_none, false)
|
45
45
|
@backend = URI(opts[:backend]) if opts[:backend]
|
data/test/rack_proxy_test.rb
CHANGED
@@ -49,6 +49,16 @@ class RackProxyTest < Test::Unit::TestCase
|
|
49
49
|
assert_match(/(itunes|iphone|ipod|mac|ipad)/, last_response.body)
|
50
50
|
end
|
51
51
|
|
52
|
+
def test_normalize_headers
|
53
|
+
proxy_class = Rack::Proxy
|
54
|
+
headers = { 'header_array' => ['first_entry'], 'header_non_array' => :entry }
|
55
|
+
|
56
|
+
normalized_headers = proxy_class.send(:normalize_headers, headers)
|
57
|
+
assert normalized_headers.instance_of?(Rack::Utils::HeaderHash)
|
58
|
+
assert normalized_headers['header_array'] == 'first_entry'
|
59
|
+
assert normalized_headers['header_non_array'] == :entry
|
60
|
+
end
|
61
|
+
|
52
62
|
def test_header_reconstruction
|
53
63
|
proxy_class = Rack::Proxy
|
54
64
|
|
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.5.
|
4
|
+
version: 0.5.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacek Becela
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -50,8 +50,8 @@ files:
|
|
50
50
|
- Gemfile
|
51
51
|
- Gemfile.lock
|
52
52
|
- LICENSE
|
53
|
+
- README.md
|
53
54
|
- Rakefile
|
54
|
-
- Readme
|
55
55
|
- lib/net_http_hacked.rb
|
56
56
|
- lib/rack-proxy.rb
|
57
57
|
- lib/rack/http_streaming_response.rb
|
data/Readme
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
A request/response rewriting HTTP proxy. A Rack app.
|
2
|
-
|
3
|
-
Subclass Rack::Proxy and provide your rewrite_env and rewrite_response methods.
|
4
|
-
|
5
|
-
Example:
|
6
|
-
|
7
|
-
class Foo < Rack::Proxy
|
8
|
-
|
9
|
-
def rewrite_env(env)
|
10
|
-
env["HTTP_HOST"] = "example.com"
|
11
|
-
|
12
|
-
env
|
13
|
-
end
|
14
|
-
|
15
|
-
def rewrite_response(triplet)
|
16
|
-
status, headers, body = triplet
|
17
|
-
|
18
|
-
headers["X-Foo"] = "Bar"
|
19
|
-
|
20
|
-
triplet
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
Example: disable SSL session verification when proxying a server with e.g. self-signed SSL certs
|
26
|
-
|
27
|
-
class TrustingProxy < Rack::Proxy
|
28
|
-
|
29
|
-
def rewrite_env(env)
|
30
|
-
env["rack.ssl_verify_none"] = true
|
31
|
-
|
32
|
-
env
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
The same can be achieved for *all* requests going through the `Rack::Proxy` instance by using
|
38
|
-
|
39
|
-
Rack::Proxy.new(ssl_verify_none: true)
|
40
|
-
|
41
|
-
See tests for more examples.
|
42
|
-
|
43
|
-
WARNING: Doesn't work with fakeweb/webmock. Both libraries monkey-patch net/http code.
|
44
|
-
|
45
|
-
TODO: 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.
|