protocol-rack 0.18.0 → 0.20.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: 4fed6d6b2ffc0dc007d343e8f9414af4c61cd7c321cb289b6d218290977feb7f
4
- data.tar.gz: d02dd7e216b58d3bbe94e5e99b4c71d689ad8de5cb7451a67a81bcd0ade5a55a
3
+ metadata.gz: c27e5bf1536d42121ad0ce4dc5a853f0dc2ecb742413bb84b96165518202a0ae
4
+ data.tar.gz: 4e6e3713f8d48d5ef5595e9f9472861593330e5551f106366d5a6c7cc7b6e908
5
5
  SHA512:
6
- metadata.gz: df29bd96d8542e75e146d0eec4d7813f7e037fdd84e68bd08ac1f6a4cfca66b3ec176dd3167e31eedb3ae849b44059c23b0fe57a4aea8b4a2c3f55c90755b36f
7
- data.tar.gz: 6969ef3c4a7fb95083dd57697c5bcf0aee57ec1f9eee6f0b4233af56e4845513c21480cee2abc14daf320d5cf7c5c739b50448bc3d3c6023432292a6544d8876
6
+ metadata.gz: 2027afc339a462587ac9c31143ad33b6d9fca2c3432068fc7369182ecf7f1111b171a33b1b7ae4600e303e8f6a59ab12369480433d8e38acc4bc3e04ed8ca3d1
7
+ data.tar.gz: c9e376f09aaf01e32b0cc2bf395d729e1043ecc14916850bc719d8d5709b8ca148e29203f8339de2899e2466dbcb5ab918f39055ae21bd63fb1595d95a9f93b8
checksums.yaml.gz.sig CHANGED
Binary file
@@ -53,3 +53,25 @@ end
53
53
  ```
54
54
 
55
55
  The adapter automatically detects your Rack version (v2, v3, or v3.1+) and uses the appropriate implementation, ensuring compatibility without any configuration.
56
+
57
+ ### Server Adapter
58
+
59
+ Any Rack compatible server can host `Protocol::HTTP` compatible middlewares.
60
+
61
+ ``` ruby
62
+ require "protocol/http/middleware"
63
+ require "protocol/rack"
64
+
65
+ # Your native application:
66
+ middleware = Protocol::HTTP::Middleware::HelloWorld
67
+
68
+ run do |env|
69
+ # Convert the rack request to a compatible rich request object:
70
+ request = Protocol::Rack::Request[env]
71
+
72
+ # Call your application
73
+ response = middleware.call(request)
74
+
75
+ Protocol::Rack::Adapter.make_response(env, response)
76
+ end
77
+ ```
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2025, by Samuel Williams.
4
+ # Copyright, 2022-2026, by Samuel Williams.
5
5
 
6
6
  require "console"
7
7
 
@@ -76,7 +76,7 @@ module Protocol
76
76
  env[http_key] = "#{current_value},#{value}"
77
77
  end
78
78
  else
79
- env[http_key] = value
79
+ env[http_key] = value.to_s
80
80
  end
81
81
  end
82
82
  end
@@ -131,10 +131,10 @@ module Protocol
131
131
  meta[key] = value
132
132
  elsif value.is_a?(String)
133
133
  value.split("\n").each do |value|
134
- headers[key] = value
134
+ headers.add(key, value)
135
135
  end
136
136
  else
137
- headers[key] = value
137
+ headers.add(key, value)
138
138
  end
139
139
  end
140
140
 
@@ -103,10 +103,10 @@ module Protocol
103
103
  meta[key] = value
104
104
  elsif value.is_a?(Array)
105
105
  value.each do |value|
106
- headers[key] = value
106
+ headers.add(key, value)
107
107
  end
108
108
  else
109
- headers[key] = value
109
+ headers.add(key, value)
110
110
  end
111
111
  end
112
112
 
@@ -89,7 +89,7 @@ module Protocol
89
89
  # No-op.
90
90
  end
91
91
 
92
- def sysread(size, buffer = nil)
92
+ def sysread(size, buffer)
93
93
  if @body
94
94
  # User's may forget to call #close...
95
95
  if chunk = @body.read
@@ -100,13 +100,8 @@ module Protocol
100
100
  @closed = true
101
101
  end
102
102
 
103
- if buffer
104
- # If a buffer is provided, we copy the chunk into it:
105
- buffer.replace(chunk)
106
- else
107
- # Otherwise we return the chunk directly:
108
- buffer = chunk
109
- end
103
+ # The buffer is always provided, and we replace its contents:
104
+ buffer.replace(chunk)
110
105
 
111
106
  return buffer
112
107
  else
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module Rack
8
- VERSION = "0.18.0"
8
+ VERSION = "0.20.0"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2022-2025, by Samuel Williams.
3
+ Copyright, 2022-2026, by Samuel Williams.
4
4
  Copyright, 2023, by Genki Takiuchi.
5
5
  Copyright, 2025, by Francisco Mejia.
6
6
 
data/readme.md CHANGED
@@ -17,60 +17,18 @@ Please see the [project documentation](https://socketry.github.io/protocol-rack/
17
17
 
18
18
  - [Request and Response Handling](https://socketry.github.io/protocol-rack/guides/request-response/index) - This guide explains how to work with requests and responses when bridging between Rack and `Protocol::HTTP`, covering advanced use cases and edge cases.
19
19
 
20
- ### Application Adapter
21
-
22
- Given a rack application, you can adapt it for use on `async-http`:
23
-
24
- ``` ruby
25
- require "async"
26
- require "async/http/server"
27
- require "async/http/client"
28
- require "async/http/endpoint"
29
- require "protocol/rack/adapter"
30
-
31
- app = proc{|env| [200, {}, ["Hello World"]]}
32
- middleware = Protocol::Rack::Adapter.new(app)
33
-
34
- Async do
35
- endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292")
36
-
37
- server_task = Async(transient: true) do
38
- server = Async::HTTP::Server.new(middleware, endpoint)
39
- server.run
40
- end
41
-
42
- client = Async::HTTP::Client.new(endpoint)
43
- puts client.get("/").read
44
- # "Hello World"
45
- end
46
- ```
47
-
48
- ### Server Adapter
49
-
50
- While not tested, in theory any Rack compatible server can host `Protocol::HTTP` compatible middlewares.
51
-
52
- ``` ruby
53
- require "protocol/http/middleware"
54
- require "protocol/rack"
55
-
56
- # Your native application:
57
- middleware = Protocol::HTTP::Middleware::HelloWorld
58
-
59
- run do |env|
60
- # Convert the rack request to a compatible rich request object:
61
- request = Protocol::Rack::Request[env]
62
-
63
- # Call your application
64
- response = middleware.call(request)
65
-
66
- Protocol::Rack::Adapter.make_response(env, response)
67
- end
68
- ```
69
-
70
20
  ## Releases
71
21
 
72
22
  Please see the [project releases](https://socketry.github.io/protocol-rack/releases/index) for all releases.
73
23
 
24
+ ### v0.20.0
25
+
26
+ - Convert header values into strings using `to_s` so that `Headers#each` can yield non-string values if necessary.
27
+
28
+ ### v0.19.0
29
+
30
+ - Use `Headers#add` instead of `Headers#[]=` in Rack3 and Rack31 adapters, which is the correct interface for appending headers.
31
+
74
32
  ### v0.18.0
75
33
 
76
34
  - Correctly invoke `rack.response_finished` in reverse order.
data/releases.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Releases
2
2
 
3
+ ## v0.20.0
4
+
5
+ - Convert header values into strings using `to_s` so that `Headers#each` can yield non-string values if necessary.
6
+
7
+ ## v0.19.0
8
+
9
+ - Use `Headers#add` instead of `Headers#[]=` in Rack3 and Rack31 adapters, which is the correct interface for appending headers.
10
+
3
11
  ## v0.18.0
4
12
 
5
13
  - Correctly invoke `rack.response_finished` in reverse order.
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.18.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
- rubygems_version: 3.6.9
131
+ rubygems_version: 4.0.3
132
132
  specification_version: 4
133
133
  summary: An implementation of the Rack protocol/specification.
134
134
  test_files: []
metadata.gz.sig CHANGED
Binary file