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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/getting-started.md +22 -0
- data/lib/protocol/rack/adapter/generic.rb +2 -2
- data/lib/protocol/rack/adapter/rack2.rb +2 -2
- data/lib/protocol/rack/adapter/rack3.rb +2 -2
- data/lib/protocol/rack/input.rb +3 -8
- data/lib/protocol/rack/version.rb +1 -1
- data/license.md +1 -1
- data/readme.md +8 -50
- data/releases.md +8 -0
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c27e5bf1536d42121ad0ce4dc5a853f0dc2ecb742413bb84b96165518202a0ae
|
|
4
|
+
data.tar.gz: 4e6e3713f8d48d5ef5595e9f9472861593330e5551f106366d5a6c7cc7b6e908
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2027afc339a462587ac9c31143ad33b6d9fca2c3432068fc7369182ecf7f1111b171a33b1b7ae4600e303e8f6a59ab12369480433d8e38acc4bc3e04ed8ca3d1
|
|
7
|
+
data.tar.gz: c9e376f09aaf01e32b0cc2bf395d729e1043ecc14916850bc719d8d5709b8ca148e29203f8339de2899e2466dbcb5ab918f39055ae21bd63fb1595d95a9f93b8
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/context/getting-started.md
CHANGED
|
@@ -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-
|
|
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
|
|
134
|
+
headers.add(key, value)
|
|
135
135
|
end
|
|
136
136
|
else
|
|
137
|
-
headers
|
|
137
|
+
headers.add(key, value)
|
|
138
138
|
end
|
|
139
139
|
end
|
|
140
140
|
|
data/lib/protocol/rack/input.rb
CHANGED
|
@@ -89,7 +89,7 @@ module Protocol
|
|
|
89
89
|
# No-op.
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
def sysread(size, buffer
|
|
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
|
-
|
|
104
|
-
|
|
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
|
data/license.md
CHANGED
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.
|
|
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:
|
|
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
|