protocol-rack 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0af7fbf35d4f83edafd70b0e20722bab2e87a17be42847ba3deb15b65c226f54
4
- data.tar.gz: 61086ed511f8f01457daefe952847124748177b0137689772afe73104fa525e6
3
+ metadata.gz: 30e960af55f8f9e0c401657bd0e245c448f46315ef97cdd3d25aeeb8f41ef99c
4
+ data.tar.gz: 1d4f9d858799b04e909776e120f4f376aa54ad4a956bd077e109edc704f3a2ff
5
5
  SHA512:
6
- metadata.gz: 87ea16543d6d9ca388911a4bd9af7e59d5ed0f46f8b20085ba305881a8efa4568998941bc3ffcf9ab7de71e6f39b1340db3fa0d605ef028cbce9be66162ad104
7
- data.tar.gz: 2e5ca7f57c8b66c04a1ecfdd8db0c15009f769e54521c29c2fae220f7c915872b39bc8acdcc5eb186a9655d96b40567b73dd312bf1626f3a15569ab1e182ac4b
6
+ metadata.gz: c71e270584bfe6e4da54ce6b175664880180ddf5ba2cb5fec1fb4ef3b67aa93af2ef78ecc0d74869f477caed03e5caf4e072758fef7f831fcb8e249ccea60e5f
7
+ data.tar.gz: 9af0d3f0bbd79784f9f8464a1cffdfc76f55e9d49e386a9c770b43af85da2a2d1a0dfd0bbb624d2465d99f79ae1ef2663848d38195a2816aa57ebb9a9588a926
checksums.yaml.gz.sig CHANGED
Binary file
@@ -90,10 +90,8 @@ module Protocol
90
90
  # HTTP/2 prefers `:authority` over `host`, so we do this for backwards compatibility.
91
91
  env[CGI::HTTP_HOST] ||= request.authority
92
92
 
93
- if request.respond_to?(:remote_address)
94
- if remote_address = request.remote_address
95
- env[CGI::REMOTE_ADDR] = remote_address.ip_address if remote_address.ip?
96
- end
93
+ if peer = request.peer
94
+ env[CGI::REMOTE_ADDR] = peer.ip_address
97
95
  end
98
96
  end
99
97
 
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2022-2024, by Samuel Williams.
5
+
6
+ require "console"
7
+
8
+ require_relative "rack3"
9
+
10
+ module Protocol
11
+ module Rack
12
+ module Adapter
13
+ class Rack31 < Rack3
14
+ def make_environment(request)
15
+ request_path, query_string = request.path.split("?", 2)
16
+ server_name, server_port = (request.authority || "").split(":", 2)
17
+
18
+ env = {
19
+ PROTOCOL_HTTP_REQUEST => request,
20
+
21
+ RACK_ERRORS => $stderr,
22
+ RACK_LOGGER => self.logger,
23
+
24
+ # The request protocol, either from the upgrade header or the HTTP/2 pseudo header of the same name.
25
+ RACK_PROTOCOL => request.protocol,
26
+
27
+ # The response finished callbacks:
28
+ RACK_RESPONSE_FINISHED => [],
29
+
30
+ # The HTTP request method, such as “GET” or “POST”. This cannot ever be an empty string, and so is always required.
31
+ CGI::REQUEST_METHOD => request.method,
32
+
33
+ # The initial portion of the request URL's “path” that corresponds to the application object, so that the application knows its virtual “location”. This may be an empty string, if the application corresponds to the “root” of the server.
34
+ CGI::SCRIPT_NAME => "",
35
+
36
+ # The remainder of the request URL's “path”, designating the virtual “location” of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash. This value may be percent-encoded when originating from a URL.
37
+ CGI::PATH_INFO => request_path,
38
+ CGI::REQUEST_PATH => request_path,
39
+ CGI::REQUEST_URI => request.path,
40
+
41
+ # The portion of the request URL that follows the ?, if any. May be empty, but is always required!
42
+ CGI::QUERY_STRING => query_string || "",
43
+
44
+ # The server protocol (e.g. HTTP/1.1):
45
+ CGI::SERVER_PROTOCOL => request.version,
46
+
47
+ # The request scheme:
48
+ RACK_URL_SCHEME => request.scheme,
49
+
50
+ # I'm not sure what sane defaults should be here:
51
+ CGI::SERVER_NAME => server_name,
52
+ CGI::SERVER_PORT => server_port,
53
+ }
54
+
55
+ if body = request.body
56
+ if body.empty?
57
+ body.close
58
+ else
59
+ env[RACK_INPUT] = Input.new(body)
60
+ end
61
+ end
62
+
63
+ self.unwrap_request(request, env)
64
+
65
+ return env
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -5,15 +5,19 @@
5
5
 
6
6
  require "rack"
7
7
 
8
- require_relative "adapter/rack2"
9
- require_relative "adapter/rack3"
10
-
11
8
  module Protocol
12
9
  module Rack
13
10
  module Adapter
14
- if ::Rack.release >= "3"
11
+ VERSION = ENV.fetch("PROTOCOL_RACK_ADAPTER_VERSION", ::Rack.release)
12
+
13
+ if VERSION >= "3.1"
14
+ require_relative "adapter/rack31"
15
+ IMPLEMENTATION = Rack31
16
+ elsif VERSION >= "3"
17
+ require_relative "adapter/rack3"
15
18
  IMPLEMENTATION = Rack3
16
19
  else
20
+ require_relative "adapter/rack2"
17
21
  IMPLEMENTATION = Rack2
18
22
  end
19
23
 
@@ -89,6 +89,13 @@ module Protocol
89
89
  if @body
90
90
  # User's may forget to call #close...
91
91
  if chunk = @body.read
92
+ # If the user reads exactly the content length, we close the stream automatically:
93
+ # https://github.com/socketry/async-http/issues/183
94
+ if @body.empty?
95
+ @body.close
96
+ @body = nil
97
+ end
98
+
92
99
  return chunk
93
100
  else
94
101
  # So if we are at the end of the stream, we close it automatically:
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module Rack
8
- VERSION = "0.10.0"
8
+ VERSION = "0.11.0"
9
9
  end
10
10
  end
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.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -38,7 +38,7 @@ cert_chain:
38
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
40
  -----END CERTIFICATE-----
41
- date: 2024-09-24 00:00:00.000000000 Z
41
+ date: 2024-11-09 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: protocol-http
@@ -46,14 +46,14 @@ dependencies:
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '0.37'
49
+ version: '0.43'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '0.37'
56
+ version: '0.43'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rack
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +79,7 @@ files:
79
79
  - lib/protocol/rack/adapter/generic.rb
80
80
  - lib/protocol/rack/adapter/rack2.rb
81
81
  - lib/protocol/rack/adapter/rack3.rb
82
+ - lib/protocol/rack/adapter/rack31.rb
82
83
  - lib/protocol/rack/body.rb
83
84
  - lib/protocol/rack/body/enumerable.rb
84
85
  - lib/protocol/rack/body/input_wrapper.rb
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  - !ruby/object:Gem::Version
113
114
  version: '0'
114
115
  requirements: []
115
- rubygems_version: 3.5.11
116
+ rubygems_version: 3.5.22
116
117
  signing_key:
117
118
  specification_version: 4
118
119
  summary: An implementation of the Rack protocol/specification.
metadata.gz.sig CHANGED
Binary file