protocol-rack 0.2.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/rack/adapter/generic.rb +27 -1
- data/lib/protocol/rack/adapter/rack2.rb +4 -6
- data/lib/protocol/rack/adapter.rb +2 -2
- data/lib/protocol/rack/constants.rb +5 -0
- data/lib/protocol/rack/input.rb +7 -3
- data/lib/protocol/rack/request.rb +4 -5
- data/lib/protocol/rack/version.rb +2 -2
- data/license.md +2 -1
- data/readme.md +8 -0
- data.tar.gz.sig +0 -0
- metadata +5 -88
- 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: a51b0412866f66870722a8f62008d4e76df2ba1d613af62b94eea1a30618bd97
|
4
|
+
data.tar.gz: 0cc84245f1dbb289cb1081f4c7c291a0bb3d69498b2d822290937418af7dc532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed7a6592a103ecc2f285aa51a83427f29b15fe95cd7488ce57f59878598b833765774db65c5f8563d67e2ac7fe1da01a5f6c58dda6c0e09b34cbdc5fa12d5384
|
7
|
+
data.tar.gz: 8182ea7a512bec710d122cdf5ee4f4538b263ef03d2b7eb99130102126c536a58cd2057cf986a9336cad9169eabcffe61ed3c9560d912445a980cdc384311ee8
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2022, by Samuel Williams.
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'console'
|
7
7
|
|
@@ -68,6 +68,16 @@ module Protocol
|
|
68
68
|
|
69
69
|
self.unwrap_headers(request.headers, env)
|
70
70
|
|
71
|
+
# For the sake of compatibility, we set the `HTTP_UPGRADE` header to the requested protocol.
|
72
|
+
if protocol = request.protocol and request.version.start_with?('HTTP/1')
|
73
|
+
env[CGI::HTTP_UPGRADE] = Array(protocol).join(",")
|
74
|
+
end
|
75
|
+
|
76
|
+
if request.respond_to?(:hijack?) and request.hijack?
|
77
|
+
env[RACK_IS_HIJACK] = true
|
78
|
+
env[RACK_HIJACK] = proc{request.hijack!.io.dup}
|
79
|
+
end
|
80
|
+
|
71
81
|
# HTTP/2 prefers `:authority` over `host`, so we do this for backwards compatibility.
|
72
82
|
env[CGI::HTTP_HOST] ||= request.authority
|
73
83
|
|
@@ -78,6 +88,12 @@ module Protocol
|
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
91
|
+
def make_environment(request)
|
92
|
+
{
|
93
|
+
request: request
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
81
97
|
# Build a rack `env` from the incoming request and apply it to the rack middleware.
|
82
98
|
#
|
83
99
|
# @parameter request [Protocol::HTTP::Request] The incoming request.
|
@@ -86,6 +102,16 @@ module Protocol
|
|
86
102
|
|
87
103
|
status, headers, body = @app.call(env)
|
88
104
|
|
105
|
+
# The status must always be an integer.
|
106
|
+
unless status.is_a?(Integer)
|
107
|
+
raise ArgumentError, "Status must be an integer!"
|
108
|
+
end
|
109
|
+
|
110
|
+
# Headers must always be a hash or equivalent.
|
111
|
+
unless headers
|
112
|
+
raise ArgumentError, "Headers must not be nil!"
|
113
|
+
end
|
114
|
+
|
89
115
|
headers, meta = self.wrap_headers(headers)
|
90
116
|
|
91
117
|
return Response.wrap(env, status, headers, meta, body, request)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2022, by Samuel Williams.
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'console'
|
7
7
|
|
@@ -17,9 +17,6 @@ module Protocol
|
|
17
17
|
RACK_MULTIPROCESS = 'rack.multiprocess'
|
18
18
|
RACK_RUN_ONCE = 'rack.run_once'
|
19
19
|
|
20
|
-
RACK_IS_HIJACK = 'rack.hijack?'
|
21
|
-
RACK_HIJACK = 'rack.hijack'
|
22
|
-
|
23
20
|
def self.wrap(app)
|
24
21
|
Rewindable.new(self.new(app))
|
25
22
|
end
|
@@ -108,10 +105,12 @@ module Protocol
|
|
108
105
|
|
109
106
|
if key.start_with?('rack.')
|
110
107
|
meta[key] = value
|
111
|
-
|
108
|
+
elsif value.is_a?(String)
|
112
109
|
value.split("\n").each do |value|
|
113
110
|
headers[key] = value
|
114
111
|
end
|
112
|
+
else
|
113
|
+
headers[key] = value
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
@@ -124,7 +123,6 @@ module Protocol
|
|
124
123
|
|
125
124
|
if protocol = response.protocol
|
126
125
|
headers['rack.protocol'] = protocol
|
127
|
-
# headers['upgrade'] = protocol
|
128
126
|
end
|
129
127
|
|
130
128
|
if body = response.body and body.stream?
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2022, by Samuel Williams.
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'rack'
|
7
7
|
|
@@ -11,7 +11,7 @@ require_relative 'adapter/rack3'
|
|
11
11
|
module Protocol
|
12
12
|
module Rack
|
13
13
|
module Adapter
|
14
|
-
if ::Rack
|
14
|
+
if ::Rack.release >= "3"
|
15
15
|
IMPLEMENTATION = Rack3
|
16
16
|
else
|
17
17
|
IMPLEMENTATION = Rack2
|
@@ -11,6 +11,7 @@ module Protocol
|
|
11
11
|
# CGI keys <https://tools.ietf.org/html/rfc3875#section-4.1>:
|
12
12
|
module CGI
|
13
13
|
HTTP_HOST = 'HTTP_HOST'
|
14
|
+
HTTP_UPGRADE = "HTTP_UPGRADE"
|
14
15
|
PATH_INFO = 'PATH_INFO'
|
15
16
|
REQUEST_METHOD = 'REQUEST_METHOD'
|
16
17
|
REQUEST_PATH = 'REQUEST_PATH'
|
@@ -35,5 +36,9 @@ module Protocol
|
|
35
36
|
RACK_URL_SCHEME = 'rack.url_scheme'
|
36
37
|
RACK_PROTOCOL = 'rack.protocol'
|
37
38
|
RACK_RESPONSE_FINISHED = 'rack.response_finished'
|
39
|
+
|
40
|
+
# Rack hijack support:
|
41
|
+
RACK_IS_HIJACK = 'rack.hijack?'
|
42
|
+
RACK_HIJACK = 'rack.hijack'
|
38
43
|
end
|
39
44
|
end
|
data/lib/protocol/rack/input.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2022, by Samuel Williams.
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2023, by Genki Takiuchi.
|
5
6
|
|
6
7
|
require 'async/io/buffer'
|
7
8
|
require 'protocol/http/body/stream'
|
@@ -18,6 +19,7 @@ module Protocol
|
|
18
19
|
# @parameter body [Protocol::HTTP::Body::Readable]
|
19
20
|
def initialize(body)
|
20
21
|
@body = body
|
22
|
+
@closed = false
|
21
23
|
|
22
24
|
# Will hold remaining data in `#read`.
|
23
25
|
@buffer = nil
|
@@ -46,6 +48,8 @@ module Protocol
|
|
46
48
|
|
47
49
|
# Close the input and output bodies.
|
48
50
|
def close(error = nil)
|
51
|
+
@closed = true
|
52
|
+
|
49
53
|
if @body
|
50
54
|
@body.close(error)
|
51
55
|
@body = nil
|
@@ -74,7 +78,7 @@ module Protocol
|
|
74
78
|
|
75
79
|
# Whether the stream has been closed.
|
76
80
|
def closed?
|
77
|
-
@body.nil?
|
81
|
+
@closed or @body.nil?
|
78
82
|
end
|
79
83
|
|
80
84
|
# Whether there are any input chunks remaining?
|
@@ -87,7 +91,7 @@ module Protocol
|
|
87
91
|
def read_next
|
88
92
|
if @body
|
89
93
|
@body.read
|
90
|
-
|
94
|
+
elsif @closed
|
91
95
|
raise IOError, "Stream is not readable, input has been closed!"
|
92
96
|
end
|
93
97
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2022, by Samuel Williams.
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'protocol/http/request'
|
7
7
|
require 'protocol/http/headers'
|
8
8
|
|
9
|
+
require_relative 'constants'
|
9
10
|
require_relative 'body/input_wrapper'
|
10
11
|
|
11
12
|
module Protocol
|
@@ -30,19 +31,17 @@ module Protocol
|
|
30
31
|
)
|
31
32
|
end
|
32
33
|
|
33
|
-
HTTP_UPGRADE = 'HTTP_UPGRADE'
|
34
|
-
|
35
34
|
def self.protocol(env)
|
36
35
|
if protocols = env['rack.protocol']
|
37
36
|
return Array(protocols)
|
38
|
-
elsif protocols = env[HTTP_UPGRADE]
|
37
|
+
elsif protocols = env[CGI::HTTP_UPGRADE]
|
39
38
|
return protocols.split(/\s*,\s*/)
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
42
|
def self.headers(env)
|
44
43
|
headers = ::Protocol::HTTP::Headers.new
|
45
|
-
env.each do |key, value|
|
44
|
+
env.each do |key, value|
|
46
45
|
if key.start_with?('HTTP_')
|
47
46
|
next if key == 'HTTP_HOST'
|
48
47
|
headers[key[5..-1].gsub('_', '-').downcase] = value
|
data/license.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# MIT License
|
2
2
|
|
3
|
-
Copyright, 2022, by Samuel Williams.
|
3
|
+
Copyright, 2022-2023, by Samuel Williams.
|
4
|
+
Copyright, 2023, by Genki Takiuchi.
|
4
5
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
7
|
of this software and associated documentation files (the "Software"), to deal
|
data/readme.md
CHANGED
@@ -71,6 +71,14 @@ We welcome contributions to this project.
|
|
71
71
|
4. Push to the branch (`git push origin my-new-feature`).
|
72
72
|
5. Create new Pull Request.
|
73
73
|
|
74
|
+
### Developer Certificate of Origin
|
75
|
+
|
76
|
+
This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
|
77
|
+
|
78
|
+
### Contributor Covenant
|
79
|
+
|
80
|
+
This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
|
81
|
+
|
74
82
|
## See Also
|
75
83
|
|
76
84
|
- [protocol-http](https://github.com/socketry/protocol-http) — General abstractions for HTTP client/server implementations.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
+
- Genki Takiuchi
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain:
|
@@ -37,7 +38,7 @@ cert_chain:
|
|
37
38
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
39
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
40
|
-----END CERTIFICATE-----
|
40
|
-
date:
|
41
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
41
42
|
dependencies:
|
42
43
|
- !ruby/object:Gem::Dependency
|
43
44
|
name: protocol-http
|
@@ -67,90 +68,6 @@ dependencies:
|
|
67
68
|
- - ">="
|
68
69
|
- !ruby/object:Gem::Version
|
69
70
|
version: '1.0'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: async-http
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0.59'
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '0.59'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: bake-test
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '0.1'
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0.1'
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: bake-test-external
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - "~>"
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: '0.1'
|
105
|
-
type: :development
|
106
|
-
prerelease: false
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
108
|
-
requirements:
|
109
|
-
- - "~>"
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: '0.1'
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: covered
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - "~>"
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '0.16'
|
119
|
-
type: :development
|
120
|
-
prerelease: false
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
requirements:
|
123
|
-
- - "~>"
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0.16'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: sus
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
requirements:
|
130
|
-
- - "~>"
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version: '0.12'
|
133
|
-
type: :development
|
134
|
-
prerelease: false
|
135
|
-
version_requirements: !ruby/object:Gem::Requirement
|
136
|
-
requirements:
|
137
|
-
- - "~>"
|
138
|
-
- !ruby/object:Gem::Version
|
139
|
-
version: '0.12'
|
140
|
-
- !ruby/object:Gem::Dependency
|
141
|
-
name: sus-fixtures-async-http
|
142
|
-
requirement: !ruby/object:Gem::Requirement
|
143
|
-
requirements:
|
144
|
-
- - "~>"
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
version: '0.1'
|
147
|
-
type: :development
|
148
|
-
prerelease: false
|
149
|
-
version_requirements: !ruby/object:Gem::Requirement
|
150
|
-
requirements:
|
151
|
-
- - "~>"
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
version: '0.1'
|
154
71
|
description:
|
155
72
|
email:
|
156
73
|
executables: []
|
@@ -186,14 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
103
|
requirements:
|
187
104
|
- - ">="
|
188
105
|
- !ruby/object:Gem::Version
|
189
|
-
version: '
|
106
|
+
version: '3.0'
|
190
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
108
|
requirements:
|
192
109
|
- - ">="
|
193
110
|
- !ruby/object:Gem::Version
|
194
111
|
version: '0'
|
195
112
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
113
|
+
rubygems_version: 3.4.22
|
197
114
|
signing_key:
|
198
115
|
specification_version: 4
|
199
116
|
summary: An implementation of the Rack protocol/specification.
|
metadata.gz.sig
CHANGED
Binary file
|