rack-proxy 0.7.4 → 0.7.5

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
  SHA256:
3
- metadata.gz: 896fa421268e5b014853a876ec69e499e5e48b5befd5c7438ffacd4094ceeb75
4
- data.tar.gz: dfcdf003e020c8590eaaf1dd0a531f0a516b85ece47898261611e5149bd81411
3
+ metadata.gz: fb78b8ebb5f71066481f1cbbf87fe0709b9a89d7da3da1ed86d5a095a4cb8ebb
4
+ data.tar.gz: aeeff912be2bf0bc5b75cae9f94192c2feae70742d734a2bd7fbf247cfd7c091
5
5
  SHA512:
6
- metadata.gz: 16d0245d20d2144d34fbbb15f23ba719dd189c8d9e9166caf55c13e3492406a3af9803f76b6ae07b10c1d6700385caf2d41825188554834ef010a90af666250e
7
- data.tar.gz: f477d57ddd81d95f95e700952daf8168d4001098cc458b5aac2599cafc0847923ed25cd0ea6aed711e9bae6461b54a7e826f0d4ea34737a6b440bf961ba21251
6
+ metadata.gz: 557cf33c379e4e2847196fd77c5bdc25c802fcc0ac112cd56780459145927b664dad1d86ccaf9d2f65eadf3ce1faedc2c26e8bdc84ac79ef8eb40f98f57c604e
7
+ data.tar.gz: edc8229c7b4a936d9a4f9f1717cd0f07144597b54fae6a89f5d528692436cb6005ae01778a603f20748518ba2b034c161de576d917abb8789632e0040378916d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-proxy (0.7.4)
4
+ rack-proxy (0.7.5)
5
5
  rack
6
6
 
7
7
  GEM
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.4'
9
+ gem 'rack-proxy', '~> 0.7.5'
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.4'`
139
+ # a. `gem 'rack-proxy', '~> 0.7.5'`
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`
@@ -29,9 +29,7 @@ module Rack
29
29
  alias_method :status, :code
30
30
 
31
31
  def headers
32
- Utils::HeaderHash.new.tap do |h|
33
- response.to_hash.each { |k, v| h[k] = v }
34
- end
32
+ Rack::Proxy.build_header_hash(response.to_hash)
35
33
  end
36
34
 
37
35
  # Can be called only once!
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.4".freeze
8
+ VERSION = "0.7.5".freeze
9
9
 
10
10
  HOP_BY_HOP_HEADERS = {
11
11
  'connection' => true,
@@ -24,11 +24,7 @@ module Rack
24
24
  !(/^HTTP_[A-Z0-9_\.]+$/ === k) || v.nil?
25
25
  end.map do |k, v|
26
26
  [reconstruct_header_name(k), v]
27
- end.inject(Utils::HeaderHash.new) do |hash, k_v|
28
- k, v = k_v
29
- hash[k] = v
30
- hash
31
- end
27
+ end.then { |pairs| build_header_hash(pairs) }
32
28
 
33
29
  x_forwarded_for = (headers['X-Forwarded-For'].to_s.split(/, +/) << env['REMOTE_ADDR']).join(', ')
34
30
 
@@ -39,7 +35,17 @@ module Rack
39
35
  mapped = headers.map do |k, v|
40
36
  [titleize(k), if v.is_a? Array then v.join("\n") else v end]
41
37
  end
42
- Utils::HeaderHash.new Hash[mapped]
38
+ build_header_hash Hash[mapped]
39
+ end
40
+
41
+ def build_header_hash(pairs)
42
+ if Rack.const_defined?(:Headers)
43
+ # Rack::Headers is only available from Rack 3 onward
44
+ Headers.new.tap { |headers| pairs.each { |k, v| headers[k] = v } }
45
+ else
46
+ # Rack::Utils::HeaderHash is deprecated from Rack 3 onward and is to be removed in 3.1
47
+ Utils::HeaderHash.new(pairs)
48
+ end
43
49
  end
44
50
 
45
51
  protected
@@ -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.4'`
8
+ # a. `gem 'rack-proxy', '~> 0.7.5'`
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,7 +4,7 @@ require "rack/http_streaming_response"
4
4
  class HttpStreamingResponseTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- host, req = "mockapi.io", Net::HTTP::Get.new("/")
7
+ host, req = "example.com", Net::HTTP::Get.new("/")
8
8
  @response = Rack::HttpStreamingResponse.new(req, host, 443)
9
9
  @response.use_ssl = true
10
10
  end
@@ -37,7 +37,7 @@ class HttpStreamingResponseTest < Test::Unit::TestCase
37
37
  end
38
38
 
39
39
  def test_to_s
40
- assert_equal @response.headers["Content-Length"].first.to_i, @response.body.to_s.size
40
+ assert_equal @response.headers["Content-Length"].first.to_i, @response.body.to_s.bytesize
41
41
  end
42
42
 
43
43
  def test_to_s_called_twice
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
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacek Becela
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-13 00:00:00.000000000 Z
11
+ date: 2023-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack