rack-proxy 0.5.5 → 0.5.6
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/Gemfile.lock +1 -1
- data/lib/rack/proxy.rb +8 -3
- data/test/rack_proxy_test.rb +31 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01ead5716a3297d180ef585021e3ef8f9061be22
|
4
|
+
data.tar.gz: 9492773b1b285a2265b4f5767d93b381a05f4e4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62b54b36a5276cf2cb8a16793ced71283d2fb597fc3aab91fd867c6e8f29f80e2193a3f2371afed2007a7b3866db156620599db7e9eb54d3756153588651ec1a
|
7
|
+
data.tar.gz: a895ec06fee93eb01265e47a053066859f4bf6bea21dfbf70aacb6443b5c59d6d377afecbabbc5f13680b4b867ccef08be00112f98430fa2177fae887d1a73b6
|
data/Gemfile.lock
CHANGED
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.6"
|
9
9
|
|
10
10
|
# @option opts [String, URI::HTTP] :backend Backend host to proxy requests to
|
11
11
|
def initialize(opts={})
|
@@ -49,17 +49,22 @@ module Rack
|
|
49
49
|
target_request.body_stream = source_request.body
|
50
50
|
target_request.content_length = source_request.content_length.to_i
|
51
51
|
target_request.content_type = source_request.content_type if source_request.content_type
|
52
|
+
target_request.body_stream.rewind
|
52
53
|
end
|
53
54
|
|
55
|
+
# Create a streaming response (the actual network communication is deferred, a.k.a. streamed)
|
56
|
+
target_response = HttpStreamingResponse.new(target_request, source_request.host, source_request.port)
|
57
|
+
|
54
58
|
backend = @backend || source_request
|
59
|
+
use_ssl = backend.scheme == "https"
|
55
60
|
|
56
61
|
# Create the response
|
57
62
|
if @streaming
|
58
63
|
# streaming response (the actual network communication is deferred, a.k.a. streamed)
|
59
64
|
target_response = HttpStreamingResponse.new(target_request, backend.host, backend.port)
|
60
|
-
target_response.use_ssl =
|
65
|
+
target_response.use_ssl = use_ssl
|
61
66
|
else
|
62
|
-
target_response = Net::HTTP.start(backend.host, backend.port, :use_ssl =>
|
67
|
+
target_response = Net::HTTP.start(backend.host, backend.port, :use_ssl => use_ssl) do |http|
|
63
68
|
http.request(target_request)
|
64
69
|
end
|
65
70
|
end
|
data/test/rack_proxy_test.rb
CHANGED
@@ -2,21 +2,44 @@ require "test_helper"
|
|
2
2
|
require "rack/proxy"
|
3
3
|
|
4
4
|
class RackProxyTest < Test::Unit::TestCase
|
5
|
-
class
|
5
|
+
class HostProxy < Rack::Proxy
|
6
|
+
attr_accessor :host
|
7
|
+
|
6
8
|
def rewrite_env(env)
|
7
|
-
env["HTTP_HOST"] =
|
9
|
+
env["HTTP_HOST"] = self.host || 'www.trix.pl'
|
8
10
|
env
|
9
11
|
end
|
10
12
|
end
|
11
|
-
|
12
|
-
def app
|
13
|
-
|
13
|
+
|
14
|
+
def app(opts = {})
|
15
|
+
return @app ||= HostProxy.new(opts)
|
14
16
|
end
|
15
|
-
|
16
|
-
def
|
17
|
+
|
18
|
+
def test_http_streaming
|
19
|
+
get "/"
|
20
|
+
assert last_response.ok?
|
21
|
+
assert_match(/Jacek Becela/, last_response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_http_full_request
|
25
|
+
app(:streaming => false)
|
17
26
|
get "/"
|
18
27
|
assert last_response.ok?
|
19
|
-
|
28
|
+
assert_match(/Jacek Becela/, last_response.body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_https_streaming
|
32
|
+
app.host = 'www.apple.com'
|
33
|
+
get 'https://example.com'
|
34
|
+
assert last_response.ok?
|
35
|
+
assert_match(/(itunes|iphone|ipod|mac|ipad)/, last_response.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_https_full_request
|
39
|
+
app(:streaming => false).host = 'www.apple.com'
|
40
|
+
get 'https://example.com'
|
41
|
+
assert last_response.ok?
|
42
|
+
assert_match(/(itunes|iphone|ipod|mac|ipad)/, last_response.body)
|
20
43
|
end
|
21
44
|
|
22
45
|
def test_header_reconstruction
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacek Becela
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|