protocol-rack 0.15.0 → 0.17.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/lib/protocol/rack/adapter/generic.rb +2 -2
- data/lib/protocol/rack/adapter/rack2.rb +8 -3
- data/lib/protocol/rack/body/enumerable.rb +2 -2
- data/lib/protocol/rack/request.rb +5 -5
- data/lib/protocol/rack/response.rb +2 -2
- data/lib/protocol/rack/version.rb +1 -1
- data/readme.md +34 -26
- 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: fbf78ac425bc2df269ede6fc0f60d0d674f11d0e6d3fe5dc07f8c766d534bedb
|
|
4
|
+
data.tar.gz: e348d48975f98d10401e7198a7a0317483c5b2b42641a78e46e771623c804a8b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3d717f59f06f4348fc44eba9b650cd8e99ca29ce731f5b2265e835fb95e71e1abaee47a65689903e6de48c23d1bace99c145405ad5a70de7054e2399ed202ce
|
|
7
|
+
data.tar.gz: b3fa66486f434892b3d076457d3a762fbbe1d76923c46c91e18466b00415767bded9625d13dd52cb88899b0d978915c9e3fb5c5926168ace1b1d4074d570e24e
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -114,7 +114,7 @@ module Protocol
|
|
|
114
114
|
|
|
115
115
|
if request.respond_to?(:hijack?) and request.hijack?
|
|
116
116
|
env[RACK_IS_HIJACK] = true
|
|
117
|
-
env[RACK_HIJACK] = proc{request.hijack!.io
|
|
117
|
+
env[RACK_HIJACK] = proc{request.hijack!.io}
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
# HTTP/2 prefers `:authority` over `host`, so we do this for backwards compatibility.
|
|
@@ -188,7 +188,7 @@ module Protocol
|
|
|
188
188
|
# This is the newer mechanism for protocol upgrade:
|
|
189
189
|
if env["rack.protocol"]
|
|
190
190
|
headers["rack.protocol"] = protocol
|
|
191
|
-
|
|
191
|
+
|
|
192
192
|
# Older mechanism for protocol upgrade:
|
|
193
193
|
elsif env[CGI::HTTP_UPGRADE]
|
|
194
194
|
headers["upgrade"] = protocol
|
|
@@ -44,7 +44,7 @@ module Protocol
|
|
|
44
44
|
RACK_INPUT => Input.new(request.body),
|
|
45
45
|
RACK_ERRORS => $stderr,
|
|
46
46
|
RACK_LOGGER => self.logger,
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
# The HTTP request method, such as "GET" or "POST". This cannot ever be an empty string, and so is always required.
|
|
49
49
|
CGI::REQUEST_METHOD => request.method,
|
|
50
50
|
|
|
@@ -55,7 +55,7 @@ module Protocol
|
|
|
55
55
|
CGI::PATH_INFO => request_path,
|
|
56
56
|
CGI::REQUEST_PATH => request_path,
|
|
57
57
|
CGI::REQUEST_URI => request.path,
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
# The portion of the request URL that follows the ?, if any. May be empty, but is always required!
|
|
60
60
|
CGI::QUERY_STRING => query_string || "",
|
|
61
61
|
|
|
@@ -68,7 +68,7 @@ module Protocol
|
|
|
68
68
|
# I'm not sure what sane defaults should be here:
|
|
69
69
|
CGI::SERVER_NAME => server_name,
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
# SERVER_PORT is optional but must not be set if it is not present.
|
|
73
73
|
if server_port
|
|
74
74
|
env[CGI::SERVER_PORT] = server_port
|
|
@@ -116,6 +116,11 @@ module Protocol
|
|
|
116
116
|
|
|
117
117
|
body&.close if body.respond_to?(:close)
|
|
118
118
|
|
|
119
|
+
# Rack 2 does not include `rack.response_finished` in the specification. However, if the application has set it, we will call the callbacks here as it would be extremely surprising to not do so.
|
|
120
|
+
env&.[](RACK_RESPONSE_FINISHED)&.each do |callback|
|
|
121
|
+
callback.call(env, status, headers, exception)
|
|
122
|
+
end
|
|
123
|
+
|
|
119
124
|
return failure_response(exception)
|
|
120
125
|
end
|
|
121
126
|
|
|
@@ -100,7 +100,7 @@ module Protocol
|
|
|
100
100
|
def stream?
|
|
101
101
|
!@body.respond_to?(:each)
|
|
102
102
|
end
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
# Stream the response body to the given stream.
|
|
105
105
|
# The body is automatically closed after streaming.
|
|
106
106
|
#
|
|
@@ -112,7 +112,7 @@ module Protocol
|
|
|
112
112
|
ensure
|
|
113
113
|
self.close(error)
|
|
114
114
|
end
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
# Read the next chunk from the response body.
|
|
117
117
|
# Returns nil when there are no more chunks.
|
|
118
118
|
#
|
|
@@ -23,13 +23,13 @@ module Protocol
|
|
|
23
23
|
def self.[](env)
|
|
24
24
|
env["protocol.http.request"] ||= new(env)
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
# Initialize a new Request instance from a Rack environment.
|
|
28
28
|
#
|
|
29
29
|
# @parameter env [Hash] The Rack environment hash.
|
|
30
30
|
def initialize(env)
|
|
31
31
|
@env = env
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
super(
|
|
34
34
|
@env["rack.url_scheme"],
|
|
35
35
|
@env["HTTP_HOST"],
|
|
@@ -41,7 +41,7 @@ module Protocol
|
|
|
41
41
|
self.class.protocol(@env)
|
|
42
42
|
)
|
|
43
43
|
end
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
# Extract the protocol list from the Rack environment.
|
|
46
46
|
# Checks both `rack.protocol` and `HTTP_UPGRADE` headers.
|
|
47
47
|
#
|
|
@@ -54,7 +54,7 @@ module Protocol
|
|
|
54
54
|
return protocols.split(/\s*,\s*/)
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
# Extract HTTP headers from the Rack environment.
|
|
59
59
|
# Converts Rack's `HTTP_*` environment variables to proper HTTP headers.
|
|
60
60
|
#
|
|
@@ -68,7 +68,7 @@ module Protocol
|
|
|
68
68
|
headers[key[5..-1].gsub("_", "-").downcase] = value
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
return headers
|
|
73
73
|
end
|
|
74
74
|
end
|
|
@@ -45,11 +45,11 @@ module Protocol
|
|
|
45
45
|
unless ignored.empty?
|
|
46
46
|
Console.warn(self, "Ignoring hop headers!", ignored: ignored)
|
|
47
47
|
end
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
if hijack_body = meta["rack.hijack"]
|
|
50
50
|
body = hijack_body
|
|
51
51
|
end
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
body = Body.wrap(env, status, headers, body, request&.body, request&.head?)
|
|
54
54
|
|
|
55
55
|
protocol = meta[RACK_PROTOCOL]
|
data/readme.md
CHANGED
|
@@ -18,26 +18,26 @@ Please see the [project documentation](https://socketry.github.io/protocol-rack/
|
|
|
18
18
|
Given a rack application, you can adapt it for use on `async-http`:
|
|
19
19
|
|
|
20
20
|
``` ruby
|
|
21
|
-
require
|
|
22
|
-
require
|
|
23
|
-
require
|
|
24
|
-
require
|
|
25
|
-
require
|
|
21
|
+
require "async"
|
|
22
|
+
require "async/http/server"
|
|
23
|
+
require "async/http/client"
|
|
24
|
+
require "async/http/endpoint"
|
|
25
|
+
require "protocol/rack/adapter"
|
|
26
26
|
|
|
27
27
|
app = proc{|env| [200, {}, ["Hello World"]]}
|
|
28
28
|
middleware = Protocol::Rack::Adapter.new(app)
|
|
29
29
|
|
|
30
30
|
Async do
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292")
|
|
32
|
+
|
|
33
|
+
server_task = Async(transient: true) do
|
|
34
|
+
server = Async::HTTP::Server.new(middleware, endpoint)
|
|
35
|
+
server.run
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
client = Async::HTTP::Client.new(endpoint)
|
|
39
|
+
puts client.get("/").read
|
|
40
|
+
# "Hello World"
|
|
41
41
|
end
|
|
42
42
|
```
|
|
43
43
|
|
|
@@ -46,27 +46,35 @@ end
|
|
|
46
46
|
While not tested, in theory any Rack compatible server can host `Protocol::HTTP` compatible middlewares.
|
|
47
47
|
|
|
48
48
|
``` ruby
|
|
49
|
-
require
|
|
50
|
-
require
|
|
49
|
+
require "protocol/http/middleware"
|
|
50
|
+
require "protocol/rack"
|
|
51
51
|
|
|
52
52
|
# Your native application:
|
|
53
53
|
middleware = Protocol::HTTP::Middleware::HelloWorld
|
|
54
54
|
|
|
55
|
-
run
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
run do |env|
|
|
56
|
+
# Convert the rack request to a compatible rich request object:
|
|
57
|
+
request = Protocol::Rack::Request[env]
|
|
58
|
+
|
|
59
|
+
# Call your application
|
|
60
|
+
response = middleware.call(request)
|
|
61
|
+
|
|
62
|
+
Protocol::Rack::Adapter.make_response(env, response)
|
|
63
|
+
end
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
## Releases
|
|
67
67
|
|
|
68
68
|
Please see the [project releases](https://socketry.github.io/protocol-rack/releases/index) for all releases.
|
|
69
69
|
|
|
70
|
+
### v0.17.0
|
|
71
|
+
|
|
72
|
+
- Support `rack.response_finished` in Rack 2 if it's present in the environment.
|
|
73
|
+
|
|
74
|
+
### v0.16.0
|
|
75
|
+
|
|
76
|
+
- Hijacked IO is no longer duped, as it's not retained by the original connection, and `SSLSocket` does not support duping.
|
|
77
|
+
|
|
70
78
|
### v0.15.0
|
|
71
79
|
|
|
72
80
|
- Use `IO::Stream::Readable` for the input body, which is a better tested and more robust interface.
|
data/releases.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
+
## v0.17.0
|
|
4
|
+
|
|
5
|
+
- Support `rack.response_finished` in Rack 2 if it's present in the environment.
|
|
6
|
+
|
|
7
|
+
## v0.16.0
|
|
8
|
+
|
|
9
|
+
- Hijacked IO is no longer duped, as it's not retained by the original connection, and `SSLSocket` does not support duping.
|
|
10
|
+
|
|
3
11
|
## v0.15.0
|
|
4
12
|
|
|
5
13
|
- Use `IO::Stream::Readable` for the input body, which is a better tested and more robust interface.
|
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.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
125
125
|
- !ruby/object:Gem::Version
|
|
126
126
|
version: '0'
|
|
127
127
|
requirements: []
|
|
128
|
-
rubygems_version: 3.6.
|
|
128
|
+
rubygems_version: 3.6.9
|
|
129
129
|
specification_version: 4
|
|
130
130
|
summary: An implementation of the Rack protocol/specification.
|
|
131
131
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|