rack-proxy 0.7.0 → 0.7.1
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 +3 -3
- data/README.md +2 -2
- data/lib/rack/proxy.rb +11 -7
- data/lib/rack_proxy_examples/example_service_proxy.rb +1 -1
- data/test/http_streaming_response_test.rb +10 -9
- data/test/rack_proxy_test.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0454cf1f53d8a69931260ca29af2dd21fd4ca9a99d13cf11db158d60498ba0c
|
4
|
+
data.tar.gz: f619d7cbadaa186906a41c95960e8ce869c0f21ba3eb9c9b60282d79a810b71b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe0622a53d3c76ac11a170d7f71a78240474360614425eac3d1c4555f9d3bd712c16d1a93ecb103f8683b5d6d056d65e77858e0f106879bc342301e6c35f73bd
|
7
|
+
data.tar.gz: 476194bf06dd6f244a3070e79b8771879504919df0ef1de45bfc4f883c261f6642586c06a8b64dc2df3e213702f42140e81f012b2d3ca5226d81eb2709107733
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-proxy (0.7.
|
4
|
+
rack-proxy (0.7.1)
|
5
5
|
rack
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
power_assert (0.2.6)
|
11
|
-
rack (2.
|
11
|
+
rack (2.2.3)
|
12
12
|
rack-test (0.5.6)
|
13
13
|
rack (>= 1.0)
|
14
|
-
rake (13.0.
|
14
|
+
rake (13.0.6)
|
15
15
|
test-unit (3.1.5)
|
16
16
|
power_assert
|
17
17
|
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Installation
|
|
6
6
|
Add the following to your `Gemfile`:
|
7
7
|
|
8
8
|
```
|
9
|
-
gem 'rack-proxy', '~> 0.7.
|
9
|
+
gem 'rack-proxy', '~> 0.7.1'
|
10
10
|
```
|
11
11
|
|
12
12
|
Or install:
|
@@ -136,7 +136,7 @@ Test with `require 'rack_proxy_examples/example_service_proxy'`
|
|
136
136
|
# 1. rails new test_app
|
137
137
|
# 2. cd test_app
|
138
138
|
# 3. install Rack-Proxy in `Gemfile`
|
139
|
-
# a. `gem 'rack-proxy', '~> 0.7.
|
139
|
+
# a. `gem 'rack-proxy', '~> 0.7.1'`
|
140
140
|
# 4. install gem: `bundle install`
|
141
141
|
# 5. create `config/initializers/proxy.rb` adding this line `require 'rack_proxy_examples/example_service_proxy'`
|
142
142
|
# 6. run: `SERVICE_URL=http://guides.rubyonrails.org rails server`
|
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.7.
|
8
|
+
VERSION = "0.7.1"
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def extract_http_request_headers(env)
|
@@ -26,7 +26,7 @@ module Rack
|
|
26
26
|
|
27
27
|
def normalize_headers(headers)
|
28
28
|
mapped = headers.map do |k, v|
|
29
|
-
[k, if v.is_a? Array then v.join("\n") else v end]
|
29
|
+
[titleize(k), if v.is_a? Array then v.join("\n") else v end]
|
30
30
|
end
|
31
31
|
Utils::HeaderHash.new Hash[mapped]
|
32
32
|
end
|
@@ -34,7 +34,11 @@ module Rack
|
|
34
34
|
protected
|
35
35
|
|
36
36
|
def reconstruct_header_name(name)
|
37
|
-
name.sub(/^HTTP_/, "").gsub("_", "-")
|
37
|
+
titleize(name.sub(/^HTTP_/, "").gsub("_", "-"))
|
38
|
+
end
|
39
|
+
|
40
|
+
def titleize(str)
|
41
|
+
str.split("-").map(&:capitalize).join("-")
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
@@ -49,12 +53,12 @@ module Rack
|
|
49
53
|
|
50
54
|
@streaming = opts.fetch(:streaming, true)
|
51
55
|
@ssl_verify_none = opts.fetch(:ssl_verify_none, false)
|
52
|
-
@backend =
|
56
|
+
@backend = opts[:backend] ? URI(opts[:backend]) : nil
|
53
57
|
@read_timeout = opts.fetch(:read_timeout, 60)
|
54
|
-
@ssl_version = opts[:ssl_version]
|
58
|
+
@ssl_version = opts[:ssl_version]
|
55
59
|
|
56
|
-
@username = opts[:username]
|
57
|
-
@password = opts[:password]
|
60
|
+
@username = opts[:username]
|
61
|
+
@password = opts[:password]
|
58
62
|
|
59
63
|
@opts = opts
|
60
64
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# 1. rails new test_app
|
6
6
|
# 2. cd test_app
|
7
7
|
# 3. install Rack-Proxy in `Gemfile`
|
8
|
-
# a. `gem 'rack-proxy', '~> 0.7.
|
8
|
+
# a. `gem 'rack-proxy', '~> 0.7.1'`
|
9
9
|
# 4. install gem: `bundle install`
|
10
10
|
# 5. create `config/initializers/proxy.rb` adding this line `require 'rack_proxy_examples/example_service_proxy'`
|
11
11
|
# 6. run: `SERVICE_URL=http://guides.rubyonrails.org rails server`
|
@@ -4,23 +4,24 @@ require "rack/http_streaming_response"
|
|
4
4
|
class HttpStreamingResponseTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
7
|
-
host, req = "
|
8
|
-
@response = Rack::HttpStreamingResponse.new(req, host)
|
7
|
+
host, req = "mockapi.io", Net::HTTP::Get.new("/")
|
8
|
+
@response = Rack::HttpStreamingResponse.new(req, host, 443)
|
9
|
+
@response.use_ssl = true
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_streaming
|
12
13
|
# Response status
|
13
|
-
|
14
|
-
|
14
|
+
assert_equal 200, @response.status
|
15
|
+
assert_equal 200, @response.status
|
15
16
|
|
16
17
|
# Headers
|
17
18
|
headers = @response.headers
|
18
19
|
|
19
|
-
assert headers.size
|
20
|
+
assert headers.size.positive?
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
assert headers["content-length"].first.to_i
|
22
|
+
assert_match %r{text/html; ?charset=utf-8}, headers["content-type"].first.downcase
|
23
|
+
assert_equal headers["content-type"], headers["CoNtEnT-TyPe"]
|
24
|
+
assert headers["content-length"].first.to_i.positive?
|
24
25
|
|
25
26
|
# Body
|
26
27
|
chunks = []
|
@@ -28,7 +29,7 @@ class HttpStreamingResponseTest < Test::Unit::TestCase
|
|
28
29
|
chunks << chunk
|
29
30
|
end
|
30
31
|
|
31
|
-
assert chunks.size
|
32
|
+
assert chunks.size.positive?
|
32
33
|
chunks.each do |chunk|
|
33
34
|
assert chunk.is_a?(String)
|
34
35
|
end
|
data/test/rack_proxy_test.rb
CHANGED
@@ -78,10 +78,10 @@ class RackProxyTest < Test::Unit::TestCase
|
|
78
78
|
proxy_class = Rack::Proxy
|
79
79
|
|
80
80
|
header = proxy_class.send(:reconstruct_header_name, "HTTP_ABC")
|
81
|
-
assert header == "
|
81
|
+
assert header == "Abc"
|
82
82
|
|
83
83
|
header = proxy_class.send(:reconstruct_header_name, "HTTP_ABC_D")
|
84
|
-
assert header == "
|
84
|
+
assert header == "Abc-D"
|
85
85
|
end
|
86
86
|
|
87
87
|
def test_extract_http_request_headers
|
@@ -120,7 +120,7 @@ class RackProxyTest < Test::Unit::TestCase
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def test_response_header_included_Hop_by_hop
|
123
|
-
app({:streaming => true}).host = '
|
123
|
+
app({:streaming => true}).host = 'mockapi.io'
|
124
124
|
get 'https://example.com/oauth2/token/info?access_token=123'
|
125
125
|
assert !last_response.headers.key?('transfer-encoding')
|
126
126
|
end
|
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacek Becela
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|