protocol-rack 0.22.0 → 0.23.0

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: 13aa77d7f39b9732297e162e2157d6c9b3dd579b70cedc06623cdc85eea32bac
4
+ data.tar.gz: eafafa88ee86951e68fe6cd46e28f925b252e9b077ebc774c4c9f3a647935b4d
5
5
  SHA512:
6
- metadata.gz: 71724669695ee82106f8f454405aab15127a1e4a0f8e41607104bf7dee85d4f458cee2c4399f4ba8cde1dccd3a8a23daa278e33984f3e2fdbc8a4eedb16c3c2b
7
- data.tar.gz: f498823e4ef6522b1c8f3bea9e58090c87c52163237a59d6ac257233bb13cc9c3430ec18792475ddfd6bac5a2cd51fae67c49b5261c1d51fd1b71fa62d24354b
6
+ metadata.gz: 7da7c63533c0623eb000b3b435bd6358f44278cc2bbffecf670969478b239d6501a8b1bf766a867761095baf71c87228bbed6be57b0a0952c4fe6e6d0bc60e8c
7
+ data.tar.gz: 9b1f1bc5f511119bbd03f6818b3deaed7263cd80fd062829a2fe23f2bb5b0b6b086fa4904120858dc45158e5d7ecb37fb26d4b198dc48cb39e51f5d062ffa131
checksums.yaml.gz.sig CHANGED
Binary file
data/context/index.yaml CHANGED
@@ -3,6 +3,8 @@
3
3
  ---
4
4
  description: An implementation of the Rack protocol/specification.
5
5
  metadata:
6
+ bug_tracker_uri: https://github.com/socketry/protocol-rack/issues
7
+ changelog_uri: https://github.com/socketry/protocol-rack/blob/main/releases.md
6
8
  documentation_uri: https://socketry.github.io/protocol-rack/
7
9
  source_code_uri: https://github.com/socketry/protocol-rack.git
8
10
  files:
@@ -44,6 +44,10 @@ module Protocol
44
44
  raise ArgumentError, "App must be callable!" unless @app.respond_to?(:call)
45
45
  end
46
46
 
47
+ # Rack does not define an application lifecycle hook, so there is nothing to close.
48
+ def close
49
+ end
50
+
47
51
  # The logger to use for this adapter.
48
52
  #
49
53
  # @returns [Console] The console logger.
@@ -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
 
@@ -89,7 +103,7 @@ module Protocol
89
103
  # @yields {|chunk| ...}
90
104
  # @parameter chunk [String] A chunk of the response body.
91
105
  def each(&block)
92
- @body.each(&block)
106
+ @body&.each(&block)
93
107
  rescue => error
94
108
  raise
95
109
  ensure
@@ -60,10 +60,7 @@ module Protocol
60
60
  #
61
61
  # @returns [Boolean] Whether the body could be rewound.
62
62
  def rewind
63
- if @body and @body.respond_to?(:rewind)
64
- # If the body is not rewindable, this will fail.
65
- @body.rewind
66
-
63
+ if @body&.rewind
67
64
  @finished = false
68
65
  @closed = false
69
66
 
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module Rack
8
- VERSION = "0.22.0"
8
+ VERSION = "0.23.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -21,6 +21,16 @@ 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.23.0
25
+
26
+ - Respect the result of rewinding the underlying request body.
27
+ - Avoid enumerating a response body after it has been closed.
28
+ - Add the missing `console` runtime dependency.
29
+
30
+ ### v0.22.1
31
+
32
+ - Rack 2 should not use `to_ary`.
33
+
24
34
  ### v0.22.0
25
35
 
26
36
  - Prefer `Protocol::HTTP::Body::Buffered` where possible for enumerable bodies, mainly to avoid creating `Enumerable`s.
@@ -54,23 +64,31 @@ Please see the [project releases](https://socketry.github.io/protocol-rack/relea
54
64
 
55
65
  - Hijacked IO is no longer duped, as it's not retained by the original connection, and `SSLSocket` does not support duping.
56
66
 
57
- ### v0.15.0
58
-
59
- - Use `IO::Stream::Readable` for the input body, which is a better tested and more robust interface.
60
-
61
- ### v0.14.0
62
-
63
- - Handling of `HEAD` requests is now more robust.
64
-
65
67
  ## Contributing
66
68
 
67
69
  We welcome contributions to this project.
68
70
 
69
- 1. Fork it.
71
+ 1. Fork the repository.
70
72
  2. Create your feature branch (`git checkout -b my-new-feature`).
71
- 3. Commit your changes (`git commit -am 'Add some feature'`).
73
+ 3. Commit your changes (`git commit -am 'Add some feature.'`).
72
74
  4. Push to the branch (`git push origin my-new-feature`).
73
- 5. Create new Pull Request.
75
+ 5. Create a new pull request.
76
+
77
+ ### Running Tests
78
+
79
+ To run the test suite:
80
+
81
+ ``` bash
82
+ $ bundle exec sus
83
+ ```
84
+
85
+ ### Making Releases
86
+
87
+ To make a new release:
88
+
89
+ ``` bash
90
+ $ bundle exec bake gem:release:patch # or minor or major
91
+ ```
74
92
 
75
93
  ### Developer Certificate of Origin
76
94
 
data/releases.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Releases
2
2
 
3
+ ## v0.23.0
4
+
5
+ - Respect the result of rewinding the underlying request body.
6
+ - Avoid enumerating a response body after it has been closed.
7
+ - Add the missing `console` runtime dependency.
8
+
9
+ ## v0.22.1
10
+
11
+ - Rack 2 should not use `to_ary`.
12
+
3
13
  ## v0.22.0
4
14
 
5
15
  - 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.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -40,6 +40,20 @@ cert_chain:
40
40
  -----END CERTIFICATE-----
41
41
  date: 1980-01-02 00:00:00.000000000 Z
42
42
  dependencies:
43
+ - !ruby/object:Gem::Dependency
44
+ name: console
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.0'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: io-stream
45
59
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +109,7 @@ files:
95
109
  - lib/protocol/rack/adapter/rack2.rb
96
110
  - lib/protocol/rack/adapter/rack3.rb
97
111
  - lib/protocol/rack/adapter/rack31.rb
112
+ - lib/protocol/rack/adapter/version.rb
98
113
  - lib/protocol/rack/body.rb
99
114
  - lib/protocol/rack/body/enumerable.rb
100
115
  - lib/protocol/rack/body/input_wrapper.rb
@@ -112,6 +127,8 @@ homepage: https://github.com/socketry/protocol-rack
112
127
  licenses:
113
128
  - MIT
114
129
  metadata:
130
+ bug_tracker_uri: https://github.com/socketry/protocol-rack/issues
131
+ changelog_uri: https://github.com/socketry/protocol-rack/blob/main/releases.md
115
132
  documentation_uri: https://socketry.github.io/protocol-rack/
116
133
  source_code_uri: https://github.com/socketry/protocol-rack.git
117
134
  rdoc_options: []
@@ -128,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
145
  - !ruby/object:Gem::Version
129
146
  version: '0'
130
147
  requirements: []
131
- rubygems_version: 4.0.3
148
+ rubygems_version: 4.0.10
132
149
  specification_version: 4
133
150
  summary: An implementation of the Rack protocol/specification.
134
151
  test_files: []
metadata.gz.sig CHANGED
Binary file