rack-proxy 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40d0c3918840c4f9b90b67427d4a8c478955356a
4
- data.tar.gz: 453109213e345d23df63360acaf51d11b82546b8
3
+ metadata.gz: 01ead5716a3297d180ef585021e3ef8f9061be22
4
+ data.tar.gz: 9492773b1b285a2265b4f5767d93b381a05f4e4c
5
5
  SHA512:
6
- metadata.gz: b9b70f64ae873ffc4e364ad64923d2b8fdb9895cde962e6109e73296b5f331cedabf6c0ed241da7cd4249cd7f7738e3036e0b5d9cf75e92ea08e9cef8d15ad73
7
- data.tar.gz: 2a2617e59c487bf5f834bb0c328a2156fa54e020ce62e116a8e5bc5c52a17d8f5dfec18a03c3432fbab6fdb0ba27f28d74969a298380ce39d95ae15d2b6827b1
6
+ metadata.gz: 62b54b36a5276cf2cb8a16793ced71283d2fb597fc3aab91fd867c6e8f29f80e2193a3f2371afed2007a7b3866db156620599db7e9eb54d3756153588651ec1a
7
+ data.tar.gz: a895ec06fee93eb01265e47a053066859f4bf6bea21dfbf70aacb6443b5c59d6d377afecbabbc5f13680b4b867ccef08be00112f98430fa2177fae887d1a73b6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-proxy (0.5.4)
4
+ rack-proxy (0.5.5)
5
5
  rack
6
6
 
7
7
  GEM
@@ -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.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 = backend.scheme == "https"
65
+ target_response.use_ssl = use_ssl
61
66
  else
62
- target_response = Net::HTTP.start(backend.host, backend.port, :use_ssl => backend.scheme == "https") do |http|
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
@@ -2,21 +2,44 @@ require "test_helper"
2
2
  require "rack/proxy"
3
3
 
4
4
  class RackProxyTest < Test::Unit::TestCase
5
- class TrixProxy < Rack::Proxy
5
+ class HostProxy < Rack::Proxy
6
+ attr_accessor :host
7
+
6
8
  def rewrite_env(env)
7
- env["HTTP_HOST"] = "www.trix.pl"
9
+ env["HTTP_HOST"] = self.host || 'www.trix.pl'
8
10
  env
9
11
  end
10
12
  end
11
-
12
- def app
13
- TrixProxy.new
13
+
14
+ def app(opts = {})
15
+ return @app ||= HostProxy.new(opts)
14
16
  end
15
-
16
- def test_trix
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
- assert /Jacek Becela/ === last_response.body
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.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-08 00:00:00.000000000 Z
11
+ date: 2013-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack