protocol-rack 0.11.1 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 124bd6a30fd5deaa6da388f3696ab0c78e6449a4725c93c8c7ba2481e588c4c7
4
- data.tar.gz: 0453b87af7991026fa5caedb55ab17bee73be495a1487dd19790ec2de54a2b68
3
+ metadata.gz: 253756f1f94918a43327d8f107e1a614414b6c7eee787d876135454697f3f108
4
+ data.tar.gz: bfe5453d726e362ac82c06a723d941991da8d6663749a924f8a81c919f6ca798
5
5
  SHA512:
6
- metadata.gz: 5c51951538967417013133c28b8b45e38826d9620048aaacf97a2a1c7a9da8c28e19ba28e28f1297dbdabece59efef43d33f9130aacd817f04053953f4d6fbc4
7
- data.tar.gz: 7ae670685d6e90520cb889a7f03e76620ad13349e0fb94a97d3a57236bdef7f476c0378533f47ac958d13fad03a8134d5318040bfa9136c23ac9f5aa74fcf9a1
6
+ metadata.gz: 990b93f88c80068cdcf57c36ed0ff8bfeeb0e79044dab843668bf93db4eff71ce4117da113b0cac812625d178603c815ca121d8b233945772a0af289690e053c
7
+ data.tar.gz: f84b64ec28519ab67db3770d6e2dce6ee86387cbc730a283fe7fa83811da2bb0d6ff831fd05f41ca5c2e8f15b33c92e7864e6ab17ad8335ba965ff3be24505a2
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2024, by Samuel Williams.
4
+ # Copyright, 2022-2025, by Samuel Williams.
5
+ # Copyright, 2025, by Francisco Mejia.
5
6
 
6
7
  require "console"
7
8
 
@@ -59,8 +60,12 @@ module Protocol
59
60
 
60
61
  # I'm not sure what sane defaults should be here:
61
62
  CGI::SERVER_NAME => server_name,
62
- CGI::SERVER_PORT => server_port,
63
63
  }
64
+
65
+ # SERVER_PORT is optional but must not be set if it is not present.
66
+ if server_port
67
+ env[CGI::SERVER_PORT] = server_port
68
+ end
64
69
 
65
70
  self.unwrap_request(request, env)
66
71
 
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2024, by Samuel Williams.
4
+ # Copyright, 2022-2025, by Samuel Williams.
5
+ # Copyright, 2025, by Francisco Mejia.
5
6
 
6
7
  require "console"
7
8
 
@@ -55,8 +56,12 @@ module Protocol
55
56
 
56
57
  # I'm not sure what sane defaults should be here:
57
58
  CGI::SERVER_NAME => server_name,
58
- CGI::SERVER_PORT => server_port,
59
59
  }
60
+
61
+ # SERVER_PORT is optional but must not be set if it is not present.
62
+ if server_port
63
+ env[CGI::SERVER_PORT] = server_port
64
+ end
60
65
 
61
66
  self.unwrap_request(request, env)
62
67
 
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2024, by Samuel Williams.
4
+ # Copyright, 2024-2025, by Samuel Williams.
5
+ # Copyright, 2025, by Francisco Mejia.
5
6
 
6
7
  require "console"
7
8
 
@@ -46,8 +47,17 @@ module Protocol
46
47
 
47
48
  # I'm not sure what sane defaults should be here:
48
49
  CGI::SERVER_NAME => server_name,
49
- CGI::SERVER_PORT => server_port,
50
50
  }
51
+
52
+ # SERVER_PORT is optional but must not be set if it is not present.
53
+ if server_port
54
+ env[CGI::SERVER_PORT] = server_port
55
+ end
56
+
57
+ # The request protocol, either from the upgrade header or the HTTP/2 pseudo header of the same name.
58
+ if protocol = request.protocol
59
+ env[RACK_PROTOCOL] = protocol
60
+ end
51
61
 
52
62
  if body = request.body
53
63
  if body.empty?
@@ -5,6 +5,7 @@
5
5
 
6
6
  require_relative "body/streaming"
7
7
  require_relative "body/enumerable"
8
+ require_relative "constants"
8
9
  require "protocol/http/body/completable"
9
10
 
10
11
  module Protocol
@@ -12,6 +13,10 @@ module Protocol
12
13
  module Body
13
14
  CONTENT_LENGTH = "content-length"
14
15
 
16
+ def self.no_content?(status)
17
+ status == 204 or status == 205 or status == 304
18
+ end
19
+
15
20
  def self.wrap(env, status, headers, body, input = nil)
16
21
  # In no circumstance do we want this header propagating out:
17
22
  if length = headers.delete(CONTENT_LENGTH)
@@ -33,12 +38,29 @@ module Protocol
33
38
  end
34
39
  elsif body.respond_to?(:each)
35
40
  body = Body::Enumerable.wrap(body, length)
36
- else
41
+ elsif body
37
42
  body = Body::Streaming.new(body, input)
43
+ else
44
+ Console.warn(self, "Rack response body was nil, ignoring!")
38
45
  end
39
46
 
40
- if response_finished = env[RACK_RESPONSE_FINISHED] and response_finished.any?
41
- body = ::Protocol::HTTP::Body::Completable.new(body, completion_callback(response_finished, env, status, headers))
47
+ if body and no_content?(status)
48
+ unless body.empty?
49
+ Console.warn(self, "Rack response body was not empty, and status code indicates no content!", body: body, status: status)
50
+ end
51
+
52
+ body.close
53
+ body = nil
54
+ end
55
+
56
+ response_finished = env[RACK_RESPONSE_FINISHED]
57
+
58
+ if response_finished&.any?
59
+ if body
60
+ body = ::Protocol::HTTP::Body::Completable.new(body, completion_callback(response_finished, env, status, headers))
61
+ else
62
+ completion_callback(response_finished, env, status, headers).call(nil)
63
+ end
42
64
  end
43
65
 
44
66
  return body
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2024, by Samuel Williams.
4
+ # Copyright, 2022-2025, by Samuel Williams.
5
5
 
6
6
  module Protocol
7
7
  module Rack
8
- VERSION = "0.11.1"
8
+ VERSION = "0.12.0"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2022-2024, by Samuel Williams.
3
+ Copyright, 2022-2025, by Samuel Williams.
4
4
  Copyright, 2023, by Genki Takiuchi.
5
+ Copyright, 2025, by Francisco Mejia.
5
6
 
6
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
8
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -11,6 +11,8 @@ Provides abstractions for working with the Rack specification on top of [`Protoc
11
11
 
12
12
  ## Usage
13
13
 
14
+ Please see the [project documentation](https://socketry.github.io/protocol-rack/) for more details.
15
+
14
16
  ### Application Adapter
15
17
 
16
18
  Given a rack application, you can adapt it for use on `async-http`:
@@ -61,6 +63,14 @@ run proc{|env|
61
63
  }
62
64
  ```
63
65
 
66
+ ## Releases
67
+
68
+ Please see the [project releases](https://socketry.github.io/protocol-rack/releases/index) for all releases.
69
+
70
+ ### v0.11.2
71
+
72
+ - Stop setting `env["SERVER_PORT"]` to `nil` if not present.
73
+
64
74
  ## Contributing
65
75
 
66
76
  We welcome contributions to this project.
data/releases.md ADDED
@@ -0,0 +1,5 @@
1
+ # Releases
2
+
3
+ ## v0.11.2
4
+
5
+ - Stop setting `env["SERVER_PORT"]` to `nil` if not present.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Francisco Mejia
8
9
  - Genki Takiuchi
9
- autorequire:
10
10
  bindir: bin
11
11
  cert_chain:
12
12
  - |
@@ -38,7 +38,7 @@ cert_chain:
38
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
40
  -----END CERTIFICATE-----
41
- date: 2024-12-11 00:00:00.000000000 Z
41
+ date: 2025-04-29 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: protocol-http
@@ -68,8 +68,6 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '1.0'
71
- description:
72
- email:
73
71
  executables: []
74
72
  extensions: []
75
73
  extra_rdoc_files: []
@@ -92,13 +90,13 @@ files:
92
90
  - lib/protocol/rack/version.rb
93
91
  - license.md
94
92
  - readme.md
93
+ - releases.md
95
94
  homepage: https://github.com/socketry/protocol-rack
96
95
  licenses:
97
96
  - MIT
98
97
  metadata:
99
98
  documentation_uri: https://socketry.github.io/protocol-rack/
100
99
  source_code_uri: https://github.com/socketry/protocol-rack.git
101
- post_install_message:
102
100
  rdoc_options: []
103
101
  require_paths:
104
102
  - lib
@@ -106,15 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
104
  requirements:
107
105
  - - ">="
108
106
  - !ruby/object:Gem::Version
109
- version: '3.1'
107
+ version: '3.2'
110
108
  required_rubygems_version: !ruby/object:Gem::Requirement
111
109
  requirements:
112
110
  - - ">="
113
111
  - !ruby/object:Gem::Version
114
112
  version: '0'
115
113
  requirements: []
116
- rubygems_version: 3.5.22
117
- signing_key:
114
+ rubygems_version: 3.6.2
118
115
  specification_version: 4
119
116
  summary: An implementation of the Rack protocol/specification.
120
117
  test_files: []
metadata.gz.sig CHANGED
Binary file