protocol-rack 0.14.0 → 0.16.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 +3 -3
- data/lib/protocol/rack/adapter/rack2.rb +3 -3
- data/lib/protocol/rack/body/enumerable.rb +2 -2
- data/lib/protocol/rack/input.rb +19 -9
- data/lib/protocol/rack/request.rb +5 -5
- data/lib/protocol/rack/response.rb +3 -3
- data/lib/protocol/rack/version.rb +1 -1
- data/readme.md +8 -0
- data/releases.md +8 -0
- data.tar.gz.sig +0 -0
- metadata +15 -1
- 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: 6d1c1680392355d0bf9a1aa9b6b76f2267f9d1f612e4ae194fe5933a95fb4486
|
4
|
+
data.tar.gz: 8401fd53bbe49d9547f187f06a23ba334eae3814570f041b333c8c3c30aa317b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3194c1c3ae772b58d15126fa918150b3e04791bfcf24a25ef6314d573392c3b8fdfca9efd7bab47a17ab1fd99d2b9a32323699014c900840024368fdfcabcd
|
7
|
+
data.tar.gz: ebbcaf7b1368633de01b261c1ad8c6f741f798b74d28070e33d4023887b306acb9a86df5b243f2b3bef737a148663c45a94bd981e6cf3d9757ce82048c4be830
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -114,12 +114,12 @@ 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.
|
121
121
|
env[CGI::HTTP_HOST] ||= request.authority
|
122
|
-
|
122
|
+
|
123
123
|
if peer = request.peer
|
124
124
|
env[CGI::REMOTE_ADDR] = peer.ip_address
|
125
125
|
end
|
@@ -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
|
@@ -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
|
#
|
data/lib/protocol/rack/input.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# Copyright, 2022-2025, by Samuel Williams.
|
5
5
|
# Copyright, 2023, by Genki Takiuchi.
|
6
6
|
|
7
|
-
require "
|
7
|
+
require "io/stream/readable"
|
8
8
|
|
9
9
|
module Protocol
|
10
10
|
module Rack
|
@@ -14,22 +14,21 @@ module Protocol
|
|
14
14
|
#
|
15
15
|
# This implementation is not always rewindable, to avoid buffering the input when handling large uploads. See {Rewindable} for more details.
|
16
16
|
class Input
|
17
|
+
include IO::Stream::Readable
|
18
|
+
|
17
19
|
# Initialize the input wrapper.
|
18
20
|
# @parameter body [Protocol::HTTP::Body::Readable]
|
19
|
-
def initialize(body)
|
21
|
+
def initialize(body, ...)
|
20
22
|
@body = body
|
21
23
|
@closed = false
|
22
24
|
|
23
|
-
|
24
|
-
@buffer = nil
|
25
|
+
super(...)
|
25
26
|
end
|
26
27
|
|
27
28
|
# The input body.
|
28
29
|
# @attribute [Protocol::HTTP::Body::Readable]
|
29
30
|
attr :body
|
30
31
|
|
31
|
-
include Protocol::HTTP::Body::Stream::Reader
|
32
|
-
|
33
32
|
# Enumerate chunks of the request body.
|
34
33
|
# @yields {|chunk| ...}
|
35
34
|
# @parameter chunk [String]
|
@@ -65,7 +64,6 @@ module Protocol
|
|
65
64
|
# If the body is not rewindable, this will fail.
|
66
65
|
@body.rewind
|
67
66
|
|
68
|
-
@buffer = nil
|
69
67
|
@finished = false
|
70
68
|
@closed = false
|
71
69
|
|
@@ -87,7 +85,11 @@ module Protocol
|
|
87
85
|
|
88
86
|
private
|
89
87
|
|
90
|
-
def
|
88
|
+
def flush
|
89
|
+
# No-op.
|
90
|
+
end
|
91
|
+
|
92
|
+
def sysread(size, buffer = nil)
|
91
93
|
if @body
|
92
94
|
# User's may forget to call #close...
|
93
95
|
if chunk = @body.read
|
@@ -98,7 +100,15 @@ module Protocol
|
|
98
100
|
@closed = true
|
99
101
|
end
|
100
102
|
|
101
|
-
|
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
|
110
|
+
|
111
|
+
return buffer
|
102
112
|
else
|
103
113
|
unless @closed
|
104
114
|
# So if we are at the end of the stream, we close it automatically:
|
@@ -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
|
@@ -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-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative "body"
|
7
7
|
require_relative "constants"
|
@@ -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
@@ -67,6 +67,14 @@ run proc{|env|
|
|
67
67
|
|
68
68
|
Please see the [project releases](https://socketry.github.io/protocol-rack/releases/index) for all releases.
|
69
69
|
|
70
|
+
### v0.16.0
|
71
|
+
|
72
|
+
- Hijacked IO is no longer duped, as it's not retained by the original connection, and `SSLSocket` does not support duping.
|
73
|
+
|
74
|
+
### v0.15.0
|
75
|
+
|
76
|
+
- Use `IO::Stream::Readable` for the input body, which is a better tested and more robust interface.
|
77
|
+
|
70
78
|
### v0.14.0
|
71
79
|
|
72
80
|
- Handling of `HEAD` requests is now more robust.
|
data/releases.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v0.16.0
|
4
|
+
|
5
|
+
- Hijacked IO is no longer duped, as it's not retained by the original connection, and `SSLSocket` does not support duping.
|
6
|
+
|
7
|
+
## v0.15.0
|
8
|
+
|
9
|
+
- Use `IO::Stream::Readable` for the input body, which is a better tested and more robust interface.
|
10
|
+
|
3
11
|
## v0.14.0
|
4
12
|
|
5
13
|
- Handling of `HEAD` requests is now more robust.
|
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.16.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: io-stream
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.10'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.10'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: protocol-http
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|