protocol-rack 0.22.0 → 0.22.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6af833f22e0c72b843fb6abd8497a49177d41f964087c7dea8b7c5f4c9e7036
4
- data.tar.gz: 9dd305e81599e12dce90c2a4f8f268f78e438c8268016914a373c22db15202ec
3
+ metadata.gz: 46f37b5dbbaa27c5bb42f3dd5d27ea715a425d8ca279bcaab1ed2d95f98d9cf3
4
+ data.tar.gz: 475be5c00aed56f5fb54894d0db92ecf3526de8608149c007087975fc8a3385a
5
5
  SHA512:
6
- metadata.gz: 71724669695ee82106f8f454405aab15127a1e4a0f8e41607104bf7dee85d4f458cee2c4399f4ba8cde1dccd3a8a23daa278e33984f3e2fdbc8a4eedb16c3c2b
7
- data.tar.gz: f498823e4ef6522b1c8f3bea9e58090c87c52163237a59d6ac257233bb13cc9c3430ec18792475ddfd6bac5a2cd51fae67c49b5261c1d51fd1b71fa62d24354b
6
+ metadata.gz: 6ec24d2d39e1f9ccab02dbda9336c54383a8ea5054f4d49086ed457ae9722e0f19fca2e9c36cb3cceb7c95e4d7478cd2e865fa35a8c057d0156a08d4e51aace1
7
+ data.tar.gz: 84c117df4fdae53826b5ca431ca0ca7ffb7f80208021feee09cc2fe72ad487d969da1ecdd1a4a2f016f4cf185c40eda7db99647309af6ad8cce11a6371994e1f
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ require "rack"
7
+
8
+ module Protocol
9
+ module Rack
10
+ module Adapter
11
+ # The version of Rack being used. Can be overridden using the PROTOCOL_RACK_ADAPTER_VERSION environment variable.
12
+ VERSION = ENV.fetch("PROTOCOL_RACK_ADAPTER_VERSION", ::Rack.release)
13
+ end
14
+ end
15
+ end
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2022-2026, by Samuel Williams.
5
5
 
6
- require "rack"
6
+ require_relative "adapter/version"
7
7
 
8
8
  module Protocol
9
9
  module Rack
@@ -16,9 +16,6 @@ module Protocol
16
16
  # response = adapter.call(request)
17
17
  # ```
18
18
  module Adapter
19
- # The version of Rack being used. Can be overridden using the PROTOCOL_RACK_ADAPTER_VERSION environment variable.
20
- VERSION = ENV.fetch("PROTOCOL_RACK_ADAPTER_VERSION", ::Rack.release)
21
-
22
19
  if VERSION >= "3.1"
23
20
  require_relative "adapter/rack31"
24
21
  IMPLEMENTATION = Rack31
@@ -7,6 +7,8 @@ require "protocol/http/body/readable"
7
7
  require "protocol/http/body/buffered"
8
8
  require "protocol/http/body/file"
9
9
 
10
+ require_relative "../adapter/version"
11
+
10
12
  module Protocol
11
13
  module Rack
12
14
  module Body
@@ -17,18 +19,30 @@ module Protocol
17
19
  # The content-length header key.
18
20
  CONTENT_LENGTH = "content-length".freeze
19
21
 
20
- # Wraps a Rack response body into an {Enumerable} instance.
21
- # If the body is an Array, its total size is calculated automatically.
22
- #
23
- # @parameter body [Object] The Rack response body that responds to `each`.
24
- # @parameter length [Integer] Optional content length of the response body.
25
- # @returns [Enumerable] A new enumerable body instance.
26
- def self.wrap(body, length = nil)
27
- if body.respond_to?(:to_ary)
28
- # This avoids allocating an enumerator, which is more efficient:
29
- return ::Protocol::HTTP::Body::Buffered.new(body.to_ary, length)
30
- else
31
- return self.new(body, length)
22
+ if Adapter::VERSION >= "3"
23
+ # Wraps a Rack response body into an {Enumerable} instance.
24
+ # If the body is an Array, its total size is calculated automatically.
25
+ #
26
+ # @parameter body [Object] The Rack response body that responds to `each`.
27
+ # @parameter length [Integer] Optional content length of the response body.
28
+ # @returns [Enumerable] A new enumerable body instance.
29
+ def self.wrap(body, length = nil)
30
+ if body.respond_to?(:to_ary)
31
+ # This avoids allocating an enumerator, which is more efficient:
32
+ return ::Protocol::HTTP::Body::Buffered.new(body.to_ary, length)
33
+ else
34
+ return self.new(body, length)
35
+ end
36
+ end
37
+ else
38
+ def self.wrap(body, length = nil)
39
+ # Rack 2 does not specify or implement `to_ary` behaviour correctly, so the best we can do is check if it's an Array directly:
40
+ if body.is_a?(Array)
41
+ # This avoids allocating an enumerator, which is more efficient:
42
+ return ::Protocol::HTTP::Body::Buffered.new(body, length)
43
+ else
44
+ return self.new(body, length)
45
+ end
32
46
  end
33
47
  end
34
48
 
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module Rack
8
- VERSION = "0.22.0"
8
+ VERSION = "0.22.1"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -21,6 +21,10 @@ Please see the [project documentation](https://socketry.github.io/protocol-rack/
21
21
 
22
22
  Please see the [project releases](https://socketry.github.io/protocol-rack/releases/index) for all releases.
23
23
 
24
+ ### v0.22.1
25
+
26
+ - Rack 2 should not use `to_ary`.
27
+
24
28
  ### v0.22.0
25
29
 
26
30
  - Prefer `Protocol::HTTP::Body::Buffered` where possible for enumerable bodies, mainly to avoid creating `Enumerable`s.
@@ -58,10 +62,6 @@ Please see the [project releases](https://socketry.github.io/protocol-rack/relea
58
62
 
59
63
  - Use `IO::Stream::Readable` for the input body, which is a better tested and more robust interface.
60
64
 
61
- ### v0.14.0
62
-
63
- - Handling of `HEAD` requests is now more robust.
64
-
65
65
  ## Contributing
66
66
 
67
67
  We welcome contributions to this project.
@@ -72,6 +72,22 @@ We welcome contributions to this project.
72
72
  4. Push to the branch (`git push origin my-new-feature`).
73
73
  5. Create new Pull Request.
74
74
 
75
+ ### Running Tests
76
+
77
+ To run the test suite:
78
+
79
+ ``` shell
80
+ bundle exec sus
81
+ ```
82
+
83
+ ### Making Releases
84
+
85
+ To make a new release:
86
+
87
+ ``` shell
88
+ bundle exec bake gem:release:patch # or minor or major
89
+ ```
90
+
75
91
  ### Developer Certificate of Origin
76
92
 
77
93
  In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.22.1
4
+
5
+ - Rack 2 should not use `to_ary`.
6
+
3
7
  ## v0.22.0
4
8
 
5
9
  - Prefer `Protocol::HTTP::Body::Buffered` where possible for enumerable bodies, mainly to avoid creating `Enumerable`s.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -95,6 +95,7 @@ files:
95
95
  - lib/protocol/rack/adapter/rack2.rb
96
96
  - lib/protocol/rack/adapter/rack3.rb
97
97
  - lib/protocol/rack/adapter/rack31.rb
98
+ - lib/protocol/rack/adapter/version.rb
98
99
  - lib/protocol/rack/body.rb
99
100
  - lib/protocol/rack/body/enumerable.rb
100
101
  - lib/protocol/rack/body/input_wrapper.rb
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  - !ruby/object:Gem::Version
129
130
  version: '0'
130
131
  requirements: []
131
- rubygems_version: 4.0.3
132
+ rubygems_version: 4.0.6
132
133
  specification_version: 4
133
134
  summary: An implementation of the Rack protocol/specification.
134
135
  test_files: []
metadata.gz.sig CHANGED
Binary file